DEV Community

Priya Raman
Priya Raman

Posted on • Edited 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.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Sentry mobile image

App store rankings love fast apps - mobile vitals can help you get there

Slow startup times, UI hangs, and frozen frames frustrate users—but they’re also fixable. Mobile Vitals help you measure and understand these performance issues so you can optimize your app’s speed and responsiveness. Learn how to use them to reduce friction and improve user experience.

Read full post →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay