Porwal
Porwal

Reputation: 330

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.

Upvotes: 2

Views: 6162

Answers (5)

PlusInfosys
PlusInfosys

Reputation: 3436

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!)

Upvotes: 5

Try this method:

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

Upvotes: 0

ronak patel
ronak patel

Reputation: 400

In swift 4.0

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

Upvotes: 0

Kathiresan Murugan
Kathiresan Murugan

Reputation: 2962

CIImage to UIImage

Swift 3.0

let uiImage = UIImage(CIImage: ciImage)

Upvotes: 0

emraz
emraz

Reputation: 1613

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
    }

Upvotes: 1

Related Questions