在 iOS 10 从 CIImage 创建 UIImage

Create UIImage from CIImage on iOS 10

我正在尝试为 iOS10 (https://github.com/Exygy/Titanium-Ti.Barcode)

重建 Titanium 模块

重建时,出现以下错误并且构建失败。

cannot initialize a variable of type 'UIImage *' with an rvalue of type
  'CIImage *'
UIImage *image = [blob image];
         ^       ~~~~~~~~~~~~

以下是生成它的代码片段:

id blob = [args valueForKey:@"image"];
ENSURE_TYPE(blob, TiBlob);
UIImage* image = [blob image];

我是 Objective C 的菜鸟。

您可以使用以下内容:

Objective C:

CIImage *ciImage = [blob image];
UIImage *uiImage = [[UIImage alloc] initWithCIImage:ciImage];

Swift 4.0:

let ciImage: CIImage? = blob.image()
let uiImage = UIImage(ciImage: ciImage!)

Swift 3.0

 func convertCIImagetoUIimage(cmage:CIImage) -> UIImage {
        let context:CIContext = CIContext.init(options: nil)
        let cgImage:CGImage = context.createCGImage(cmage, from: cmage.extent)!
        let image:UIImage = UIImage.init(cgImage: cgImage)
        return image
    }

试试这个方法:

CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgImage = [context createCGImage:ciImage fromRect:[ciImage extent]];
UIImage* uiImage = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);

CIImage 转 UIImage

Swift 3.0

let uiImage = UIImage(CIImage: ciImage)

在swift4.0

let ciImage: CIImage? = blob.image()
let uiImage = UIImage(ciImage: ciImage!)