Looking for hints on swiftui camera app.

hello. I am a beginner developer.

I am creating a camera app using swiftui.

I want to create an app that allows you to take pictures with a camera, apply filters, and save them.

I'm practicing following Apple's sample tutorial. https://developer.apple.com/tutorials/sample-apps/capturingphotos-camerapreview

It was possible to apply CIFilter to the image displayed in the viewfinder, but I don't know how to apply the filter to the saved photo.

I'd like to get some hints on this.

Answered by ssmith_c in 764919022

To apply a CIFilter to your photo, you first need to create a CIImage from your saved photo. You could use the init?(contentsOf: url) initializer for this. Then you can perform CIFilter operations on the CIImage.

To produce a new picture that you can save, you'll need to make a CIContext (with no destination), then use e.g. CIContext.createCGImage:fromRect

I've found these extensions to be useful: https://github.com/DigitalMasterpieces/CoreImageExtensions

Search for "write CGImage to file" for hints on how to do that. Note that neither CIImage nor CGImage are files, nor are they bitmap representations of images; they are abstract representations of "things that can be represented as an image" by their respective frameworks.

Good luck!

Accepted Answer

To apply a CIFilter to your photo, you first need to create a CIImage from your saved photo. You could use the init?(contentsOf: url) initializer for this. Then you can perform CIFilter operations on the CIImage.

To produce a new picture that you can save, you'll need to make a CIContext (with no destination), then use e.g. CIContext.createCGImage:fromRect

I've found these extensions to be useful: https://github.com/DigitalMasterpieces/CoreImageExtensions

Search for "write CGImage to file" for hints on how to do that. Note that neither CIImage nor CGImage are files, nor are they bitmap representations of images; they are abstract representations of "things that can be represented as an image" by their respective frameworks.

Good luck!

Looking for hints on swiftui camera app.
 
 
Q