I am trying to convert the following ImageMagick
command into objective-c:
convert photo.png -posterize 6 photo2.png
I'm basically just trying to take some UIImage
and apply the simple posterize effect to it. I written up the code below and it's not having any effect on the image. It is not throwing any exceptions or failing. I have a failling I'm either screwing up with the command arguments or the image input / output. Does anyone have any suggestions on how to fix this?
MagickWandGenesis();
MagickWand *wand = NewMagickWand();
NSData *data = UIImagePNGRepresentation(self.originalImage);
MagickReadImageBlob(wand, [data bytes], [data length]);
int arg_count = 2;
char *args[] = { "-posterize", "6", NULL};
ImageInfo *image_info = AcquireImageInfo();
ExceptionInfo *exception = AcquireExceptionInfo();
MagickBooleanType status = ConvertImageCommand(image_info, arg_count, args, NULL, exception);
if (exception->severity != UndefinedException)
{
status = MagickTrue;
CatchException(exception);
}
if (status == MagickFalse)
{
NSLog(@"FAIL");
}
self.imageView.image = self.originalImage;
image_info=DestroyImageInfo(image_info);
exception=DestroyExceptionInfo(exception);
DestroyMagickWand(wand);
MagickWandTerminus();