简体   繁体   中英

Create UIImage from CIImage on iOS 10

I was trying to rebuild a Titanium Module for 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.

You can use following :

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
    }

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

Swift 3.0

let uiImage = UIImage(CIImage: ciImage)

In swift 4.0

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM