我正在尝试将以下ImageMagick
命令转换为objective-c:
convert photo.png -posterize 6 photo2.png
我基本上只是想尝试一些UIImage
并将简单的posterize效果应用于它。我写了下面的代码,它对图像没有任何影响。它不会抛出任何异常或失败。我有一个惊慌失措,我要么搞砸命令参数或图像输入/输出。有没有人对如何解决这个问题有任何建议?
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();
答案 0 :(得分:1)
我相信你正在寻找Imagemagick的MagickPosterizeImage。
MagickWandGenesis();
MagickWand *wand = NewMagickWand();
NSData *data = UIImagePNGRepresentation(self.originalImage);
MagickReadImageBlob(wand, [data bytes], [data length]);
MagickBooleanType = status;
status = MagickPosterizeImage(wand,6,MagickFalse);
if (status == MagickFalse)
{
NSLog(@"FAIL");
}
// Convert wand back to UIImage
unsigned char * c_blob;
size_t data_length;
c_blob = MagickGetImageBlob(wand,&data_length);
data = [NSData dataWithBytes:c_blob length:data_length];
self.imageView.image = [UIImage imageWithData:data];
DestroyMagickWand(wand);
MagickWandTerminus();
还有MagickOrderedPosterizeImage & MagickOrderedPosterizeImageChannel来微调抖动阈值和目标颜色通道。