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.