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

后端 未结 1 1070
别跟我提以往
别跟我提以往 2020-12-04 03:30

I\'m working on a simple app. It has an image view with pre-loaded image and a button. When pressed the button should invert the image in the image view.

It works

相关标签:
1条回答
  • 2020-12-04 04:08

    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.

    0 讨论(0)
提交回复
热议问题