How to Convert UIImage to CIImage and vice versa

HelmiB picture HelmiB · Dec 8, 2011 · Viewed 57.3k times · Source

I'm trying to get CIImage from ImageView that display on the screen.

UIImage *image = myImageView.image;

convert image UIImage to CIImage.

CIImage *cImage = [....];

How to do this?

Answer

changx picture changx · Dec 8, 2011
CIImage *ciImage = [UIImage imageNamed:@"test.png"].CIImage;
UIImage *uiImage = [[UIImage alloc] initWithCIImage:ciImage];

To fix the case where myUIImage.CIImage returns nil like [UIImageView image], you can instead do [CIImage imageWithCGImage:myUIImage.CGImage] – Dylan Hand

Swift version:

let ciImage = UIImage(named: "test.png")!.ciImage
let uiImage = UIImage(ciImage: ciImage)

To fix the case where myUIImage.ciImage returns nil like you can instead do CIImage(cgImage: myUIImage!.cgImage!).