Page 1 of 1

How to convert WMF to PNG/JPEG on ImageMagick iOS library

Posted: 2015-09-11T02:04:07-07:00
by firesun57
Hi,

I downloaded the IM_Test sample project from this http://www.imagemagick.org/script/binar ... es.php#iOS link. I want to convert a wmf file to JPEG or PNG. I have used the function :

Code: Select all

- (IBAction)buttonConv04:(id)sender {
    
    // MagickWandGenesis();

    int arg_count = 4;
    char *input_image = strdup([[[NSBundle mainBundle] pathForResource:@"img_0" ofType:@"wmf"] UTF8String]);
    char *output_image = strdup([[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"png"] UTF8String]);
    char *args[] = {"convert", input_image, "-negate", output_image, NULL};

    MagickCoreGenesis(*args, MagickTrue);
    magick_wand = NewMagickWand();
    NSData * dataObject = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:[NSString stringWithUTF8String:input_image]], 1.0f);
    MagickBooleanType status;
    status = MagickReadImageBlob(magick_wand, [dataObject bytes], [dataObject length]);

    if (status == MagickFalse) {
        ThrowWandException(magick_wand);
    }

    int args_count;
    for(args_count = 0; args[args_count] != (char *)NULL; args_count++);
    
    ImageInfo *image_info = AcquireImageInfo();
    ExceptionInfo *exception = AcquireExceptionInfo();
    
    status = ConvertImageCommand(image_info, arg_count, args, NULL, exception);
    
    if (exception->severity != UndefinedException)
    {
        status = MagickTrue;
        CatchException(exception);
    }
    
    if (status == MagickFalse)
    {
        NSLog(@"FAIL");
    }
    
    NSData * dataObject2 = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:[NSString stringWithUTF8String:output_image]], 1.0f);
    status = MagickReadImageBlob(magick_wand, [dataObject2 bytes], [dataObject2 length]);
    
    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];
    
    free(input_image);
    free(output_image);
    
    image_info=DestroyImageInfo(image_info);
    exception=DestroyExceptionInfo(exception);
    
    MagickCoreTerminus();
    
    [iKK_imageView setImage:image];
}
PNG to JPEG and vice-versa works. But when I convert a WMF image the program stops. Please see the picture below to get the details.

Image


However if I convert the image from an online converter. The image is converted to png and jpeg both. Can someone please help me how can I proceed with it.


Thanks