ConvertImageCommand() and Objective-C.
Posted: 2011-09-21T15:59:18-07:00
I have the following code, which is simply meant to resize an image using:
However, with the lack of documentation in Objective-C I'm not quite sure whether I'm implemented it correctly at all.
This is what I have so far (it is simply the IM_Test.zip Xcode project) from here:
http://www.cloudgoessocial.net/im_iphone/IM_Test.zip
http://www.cloudgoessocial.net/2009/07/ ... one-xcode/
Here is my code (which sits in IM_TestViewController.m):
I'm not sure whether I'm using ImageInfo and ExceptionInfo properly considering I'm using MagickWand (do I even need this?).
Also the parameters I'm passing to ConvertImageCommand(), I'm not sure whether they are correct.
Any help would be greatly appreciated and thanks in advance.
Code: Select all
ConvertImageCommand()
This is what I have so far (it is simply the IM_Test.zip Xcode project) from here:
http://www.cloudgoessocial.net/im_iphone/IM_Test.zip
http://www.cloudgoessocial.net/2009/07/ ... one-xcode/
Here is my code (which sits in IM_TestViewController.m):
Code: Select all
- (void)convertImage {
MagickWandGenesis();
magick_wand = NewMagickWand();
//UIImageJPEGRepresentation([imageViewButton imageForState:UIControlStateNormal], 90);
NSData * dataObject = UIImagePNGRepresentation([UIImage imageNamed:@"iphone.png"]);
MagickBooleanType status;
status = MagickReadImageBlob(magick_wand, [dataObject bytes], [dataObject length]);
if (status == MagickFalse) {
ThrowWandException(magick_wand);
}
// Resize image.
ImageInfo *imageInfo = AcquireImageInfo();
ExceptionInfo *exceptionInfo = AcquireExceptionInfo();
// Get image from bundle.
char *input_image = strdup([[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"png"] UTF8String]);
char *output_image = strdup([[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"png"] UTF8String]);
char *argv[] = { "convert", input_image, "-resize", "100x100", output_image, NULL };
// ConvertImageCommand(ImageInfo *, int, char **, char **, MagickExceptionInfo *);
status = ConvertImageCommand(imageInfo, 5, argv, NULL, exceptionInfo);
free(input_image);
free(output_image);
if (status == MagickFalse) {
ThrowWandException(magick_wand); // Always throws an exception here...
}
size_t my_size;
unsigned char * my_image = MagickGetImageBlob(magick_wand, &my_size);
NSData * data = [[NSData alloc] initWithBytes:my_image length:my_size];
free(my_image);
magick_wand = DestroyMagickWand(magick_wand);
MagickWandTerminus();
UIImage * image = [[UIImage alloc] initWithData:data];
[data release];
[imageViewButton setImage:image forState:UIControlStateNormal];
[image release];
}
Also the parameters I'm passing to ConvertImageCommand(), I'm not sure whether they are correct.
Any help would be greatly appreciated and thanks in advance.