Why can’t I invert my image back to original with CIFilter in my Swift iOS app

The problem is this line:

imageView.image = UIImage(CIImage: (filter.outputImage)!)

You can’t do that. A CIImage does not magically turn into a UIImage. An image view needs a bitmap-based image, not a CIImage-based image. You have to render the CIImage to turn it into a UIImage, either by getting a CIContext and telling it to create CGImage or by drawing the CIImage into a graphics context.

Leave a Comment