Priya Raman
Posted on December 13, 2023
Steps to create a processed image based on CI filter in SwiftUI
- Create CIFilter instance to be sepia or any filter type.
- Convert selectedItem - PhotosPickerItem into Data format using loadTransferable method.
- Convert imageData into UIImage
- For Core Image processing, Image needs to be in CI format, so convert UIImage into CIImage.
- CIFilter is a specific container within Core Image that can accept input CI image and generate output CI image and apply filter in between.
- Set CurrentFilter's CI inputImg using setValue with Img key.
- Set CurrentFilter's intensity or any valid inputKeys with respective float value
- Fetch CurrentFilter's CI outputImg
- Now that processing within CI is over, its time to convert that to proper pixels in Coregraphics.
- CIContext can create cgImage with this generated CIImage with applied filter to the fullest extent size.
- Back convert from CGImage to UIImage as CIImage conversion is not needed as image has been processed.
- Back convert from UIImage to Image initializer in SwiftUI.
My Notes as understood from HackingWithSwift 100 days of SwiftUI.
💖 💪 🙅 🚩
Priya Raman
Posted on December 13, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.