DEV Community

Priya Raman
Priya Raman

Posted on • Updated on

SwiftUI - Basic Core Image Processing

Steps to create a processed image based on CI filter in SwiftUI

  1. Create CIFilter instance to be sepia or any filter type.
  2. Convert selectedItem - PhotosPickerItem into Data format using loadTransferable method.
  3. Convert imageData into UIImage
  4. For Core Image processing, Image needs to be in CI format, so convert UIImage into CIImage.
  5. CIFilter is a specific container within Core Image that can accept input CI image and generate output CI image and apply filter in between.
  6. Set CurrentFilter's CI inputImg using setValue with Img key.
  7. Set CurrentFilter's intensity or any valid inputKeys with respective float value
  8. Fetch CurrentFilter's CI outputImg
  9. Now that processing within CI is over, its time to convert that to proper pixels in Coregraphics.
  10. CIContext can create cgImage with this generated CIImage with applied filter to the fullest extent size.
  11. Back convert from CGImage to UIImage as CIImage conversion is not needed as image has been processed.
  12. Back convert from UIImage to Image initializer in SwiftUI.

My Notes as understood from HackingWithSwift 100 days of SwiftUI.

Top comments (0)