I am trying to convert a JPG image to a JP2 (JPEG 2000) format using the ImageMagick library on iOS. However, although the file extension is changing to .jp2, the format of the image does not seem to be changing. The output image is still being treated as a JPG file, and not as a true JP2 format.
Here is the code
(IBAction)convertButtonClicked:(id)sender {
NSString *jpgPath = [[NSBundle mainBundle] pathForResource:@"Example" ofType:@"jpg"];
NSString *tempFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"Converted.jp2"];
MagickWand *wand = NewMagickWand();
if (MagickReadImage(wand, [jpgPath UTF8String]) == MagickFalse) {
char *description;
ExceptionType severity;
description = MagickGetException(wand, &severity);
NSLog(@"Error reading image: %s", description);
MagickRelinquishMemory(description);
return;
}
if (MagickSetFormat(wand, "JP2") == MagickFalse) {
char *description;
ExceptionType severity;
description = MagickGetException(wand, &severity);
NSLog(@"Error setting image format to JP2: %s", description);
MagickRelinquishMemory(description);
}
if (MagickWriteImage(wand, [tempFilePath UTF8String]) == MagickFalse) {
NSLog(@"Error writing JP2 image");
return;
}
NSLog(@"Image successfully converted.");
}
@end