[英]Create UIImage from CIImage on iOS 10
I was trying to rebuild a Titanium Module for iOS10 ( https://github.com/Exygy/Titanium-Ti.Barcode )我试图为 iOS10 重建一个钛模块( https://github.com/Exygy/Titanium-Ti.Barcode )
While rebuilding, I am getting following error and the build is failing.重建时,我收到以下错误并且构建失败。
cannot initialize a variable of type 'UIImage *' with an rvalue of type
'CIImage *'
UIImage *image = [blob image];
^ ~~~~~~~~~~~~
Following is the piece of code where it is getting generated:以下是生成它的代码段:
id blob = [args valueForKey:@"image"];
ENSURE_TYPE(blob, TiBlob);
UIImage* image = [blob image];
I am a noob in the Objective C.我是 Objective C 的菜鸟。
You can use following :您可以使用以下内容:
Objective C:目标 C:
CIImage *ciImage = [blob image];
UIImage *uiImage = [[UIImage alloc] initWithCIImage:ciImage];
Swift 4.0:斯威夫特 4.0:
let ciImage: CIImage? = blob.image()
let uiImage = UIImage(ciImage: ciImage!)
Swift 3.0斯威夫特 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
}
Try this method:试试这个方法:
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgImage = [context createCGImage:ciImage fromRect:[ciImage extent]];
UIImage* uiImage = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
CIImage to UIImage CIImage 到 UIImage
Swift 3.0斯威夫特 3.0
let uiImage = UIImage(CIImage: ciImage)
In swift 4.0在 Swift 4.0
let ciImage: CIImage? = blob.image()
let uiImage = UIImage(ciImage: ciImage!)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.