Page 1 of 1

Right Way To Export Image Object To UIImage After Resize Algorithm

Posted: 2015-06-07T09:32:39-07:00
by nbyn
What is the right way to convert Image object into UIImage object with size property?

I am getting the size of image object via its signature property and then exporting it via NSData where my App Crashes.

Here is my code :

Code: Select all


-(UIImage *)applyAlgo {

MagickWandGenesis();
MagickWand * magick_wand = NewMagickWand();

NSData *imgData = UIImagePNGRepresentation(self.image);

MagickReadImageBlob(magick_wand, [imgData bytes], [imgData length]);

Image *image = GetImageFromMagickWand(magick_wand);

ExceptionInfo *exceptionInfo = AcquireExceptionInfo();

Image * newImage = InterpolativeResizeImage(image, image->columns, image->rows, BicubicInterpolatePixel, exceptionInfo);

size_t mySize = newImage->signature;

NSData *data = [[NSData alloc]initWithBytes:newImage length:mySize]; // App Crashes Here
free(newImage);

magick_wand = DestroyMagickWand(magick_wand);
MagickWandTerminus();

UIImage * finalImage = [[UIImage alloc] initWithData:data];

return finalImage;

}
Kindly help.