Pages

Monday, March 3, 2014

problems with UIImage imageWithCIImage and CIImage imageWithCGImage

Hi,

 

At some point in my phto/video processing, I have a CGImage that I need to convert to CIImage to apply some CIImage adjustments. Eventually, need to convert it to UIImage for display.

 

The code below seems to be the efficient way of doing it:

CIImage *outputImage = [CIImage imageWithCGImage:cgImage]

...do some processing with CIImage...

UIImage *finalImage = [UIImage imageWithCGImage:ref scale:1.0 orientation:imageOrientation];

 

However, it seems to rescale image introducing various artifacts, pretty much messing up the image.

 

On the other hand, if I create another copy of CGImage with:

 

CIImage *outputImage = [CIImage imageWithCGImage:cgImage]

...do some processing with CIImage...

IContext *context = [CIContext contextWithOptions:nil];

    CGImageRef ref = [context createCGImage:outputImage fromRect:outputImage.extent];

    CGImageRelease(cgImage); 

  UIImage *finalImage = [UIImage imageWithCGImage:ref scale:1.0 orientation:imageOrientation];

CGImageRelease(ref)

 

 

the photo is good - i.e. it doesn't mess up the image, but does double allocation causing huge memory spike for a full res photo - it may even crash the app.

 

1. Why is the CGImage to CIImage to UIImage as in the first example broken ?

2. What is the fix?

 

Thx.


View the original article here

0 comments:

Post a Comment