Page 1 of 1

ConvertImageCommand alway return MagickFalse

Posted: 2013-01-10T01:32:02-07:00
by boygiandi
Hi.

I'm using Image Magick for my Iphone app and I got this error :

I use this code :

Code: Select all

- (void)posterizeImageWithCompression {
	// Here we use JPEG compression.
	NSLog(@"we're using JPEG compression");
	
    // Get image from bundle.
    char *input_image = strdup([[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"png"] UTF8String]);
    char *output_image = strdup([[TMP stringByAppendingPathComponent:@"test_iphone.png"] UTF8String]);
    char *argv[] = { "convert", input_image, "-resize", "200x200", output_image, NULL };
    
	MagickCoreGenesis(*argv, MagickFalse);
	magick_wand = NewMagickWand();
	NSData * dataObject = UIImagePNGRepresentation([UIImage imageNamed:@"iphone.png"]);
	MagickBooleanType status;
	status = MagickReadImageBlob(magick_wand, [dataObject bytes], [dataObject length]);
	if (status == MagickFalse) {
		ThrowWandException(magick_wand);
	}
    
    ImageInfo *imageInfo = AcquireImageInfo();
    ExceptionInfo *exceptionInfo = AcquireExceptionInfo();
    
    // ConvertImageCommand(ImageInfo *, int, char **, char **, MagickExceptionInfo *);
    status = ConvertImageCommand(imageInfo, 5, argv, NULL, exceptionInfo);
    
    if (exceptionInfo->severity != UndefinedException)
    {
        status=MagickTrue;
        CatchException(exceptionInfo);
    }

    free(input_image);
    free(output_image);
    
    if (status == MagickFalse) {
        fprintf(stderr, "Error in call\n");
        //ThrowWandException(magick_wand); // Always throws an exception here...
    }
    
    [imageViewButton setImage:[UIImage imageWithContentsOfFile:[TMP stringByAppendingPathComponent:@"test_iphone.png"]] forState:UIControlStateNormal];
}
It can create a thumbnail and the output_image ( tmp_folder/test_iphone.png ) was generated success.
But the ConvertImageCommand alway return MagickFalse ( It alway print "Error in call" )

How to fix it ?

Thanks.