Page 1 of 1

iOS MagickReadImage() errors on device

Posted: 2012-08-17T11:50:06-07:00
by ZiggyST
Hi,
I´m using magickwand to make some filters on images like composite images using MagickCompositeImage() like photoshop. (Normal,Overlay,Diffuse,etc..),
and i´m having trouble using MagickReadImage().

I tried this code, and some variants, to read an image from file on iphone and it didn´t work(it works on simulator)

Code: Select all

...
  char *input_image = strdup([[[NSBundle mainBundle] pathForResource:path ofType:type] UTF8String]);
    MagickSetLastIterator(magick_wand);
    if(MagickReadImage(magick_wand,input_image) == MagickFalse) {
        //>>> Report an error reading the input file
        ThrowWandException(magick_wand);
    }
...
I´m getting this error:
44 CorruptImage `/var/mobile/Applications/CBA49091-DE49-4E74-B72D-86CA119707DA/MyFiltersApp.app/normal1.png' @ error/png.c/ReadPNGImage/3695

Alternative, i´m using this, and it´s working fine but it takes way too long (like 5..9 seconds) to read the image.
I can´t use JPGRepresentation() because I need the images in PNG format because they have some alpha.

Code: Select all

-(MagickWand*)magiWandWithImage:(UIImage*)theimage
{
    
    MagickWand *magick_wand = NewMagickWand();    
    NSData * objectData = UIImagePNGRepresentation(theimage);
	MagickBooleanType status = MagickReadImageBlob(magick_wand, [objectData bytes], [objectData length]);
	if (status == MagickFalse) {
		ThrowWandException(magick_wand);
	}
    return magick_wand;
}
Is there a faster or better way to do this?

Thanks in advance