我正在尝试为iOS10重建Titanium模块(https://github.com/Exygy/Titanium-Ti.Barcode)
重建时,我收到以下错误,构建失败。
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];
我是目标C中的菜鸟。
答案 0 :(得分:4)
您可以使用以下内容:
目标C:
CIImage *ciImage = [blob image];
UIImage *uiImage = [[UIImage alloc] initWithCIImage:ciImage];
Swift 4.0:
let ciImage: CIImage? = blob.image()
let uiImage = UIImage(ciImage: ciImage!)
答案 1 :(得分:1)
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
}
答案 2 :(得分:1)
试试这个方法:
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgImage = [context createCGImage:ciImage fromRect:[ciImage extent]];
UIImage* uiImage = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
答案 3 :(得分:0)
对UIImage的CIImage
Swift 3.0
let uiImage = UIImage(CIImage: ciImage)
答案 4 :(得分:0)
在swift 4.0中
let ciImage: CIImage? = blob.image()
let uiImage = UIImage(ciImage: ciImage!)