0
我想下面的命令ImageMagick
轉換成Objective-C的:翻譯ImageMagick的命令到iOS
convert photo.png -posterize 6 photo2.png
基本上,我只是想採取一些UIImage
並應用簡單的色調分離效果吧。我編寫了下面的代碼,它對圖像沒有任何影響。它不會拋出任何例外或失敗。我有一個令人失望的問題,我要麼使用命令參數或圖像輸入/輸出。有沒有人有任何建議如何解決這個問題?
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();
謝謝你,完美的工作。你碰巧知道爲什麼ConvertImageCommand可能無法工作?我仍然需要使用這個函數來轉換其他一些命令,我不相信直接API調用像posterize。 –
您需要添加'MagickCommandGenesis'來使用'ConvertImageCommand'。但是對於性能和複雜性的爭論,直接使用MagickWand/Core方法。這很簡單。 – emcconville
再次感謝,真的很感激! –