Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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.

iPhone 5, iOS 7.0.1

Posted on Jan 17, 2014 9:47 PM

Reply
1 reply

Jan 18, 2014 10:13 PM in response to RedFiveSeven

I am quite sorry - made a silly copy/paste mistake:


I am already using [UIImage imageWithCIImage] - which is where the problem is.

As posted in the question, the problem is with going from cgimage -> ciimage -> uiimage

It works fine if I make an extra conversion from ciimage back to cgimage.


The first part of the example code {that doesn't work well} is actually as folllows and not as shown above {copy/paste mistake}


CIImage *outputImage = [CIImage imageWithCGImage:cgImage]

...do some processing with CIImage...

UIImage *finalImage = [UIImage imageWithCIImage:outputImage scale:1.0 orientation:imageOrientation];

problems with UIImage imageWithCIImage and CIImage imageWithCGImage

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.