Image

Tags

#picture #image #ui #cg #ci #coreimage #uiview #photosui #uiviewcontroller #uiviewcontrollerrepresentable #typealias #phpickerviewcontroller #uiviewcontrollertype #makeuiviewcontroller #updateuiviewcontroller #kCIInputKey

Overview

Importing Image / ImagePicker

import PhotosUI
import SwiftUI

struct ImagePicker: UIViewControllerRepresentable {
    @Binding var image: UIImage?

    func makeUIViewController(context: Context) -> PHPickerViewController {
        var config = PHPickerConfiguration()
        config.filter = .images
        let picker = PHPickerViewController(configuration: config)
        picker.delegate = context.coordinator
        return picker
    }

    func updateUIViewController(_ uiViewController: PHPickerViewController, context: Context) {

    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    class Coordinator: NSObject, PHPickerViewControllerDelegate {
        let parent: ImagePicker

        init(_ parent: ImagePicker) {
            self.parent = parent
        }

        func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
            picker.dismiss(animated: true)

            guard let provider = results.first?.itemProvider else { return }

            if provider.canLoadObject(ofClass: UIImage.self) {
                provider.loadObject(ofClass: UIImage.self) { image, _ in
                    self.parent.image = image as? UIImage
                }
            }
        }
    }
}
Hacking with Swift / 100 Days / Day-65 - Importing an image into SwiftUI using PHPickerViewControllerarrow-up-right

Filtering Image

#CIFilterBuiltins

Hacking with Swift / 100 Days / Day-65 - Basic image filtering using Core Imagearrow-up-right

Saving Images

Hacking with Swift / 100 Days / Day-66 - Saving the filtered image using UIImageWriteToSavedPhotosAlbum()arrow-up-right
Hacking with Swift / 100 Days / Day-64 - How to save images to the user’s photo libraryarrow-up-right

#uiimagewritetosavedphotosalbum #saveimage

Controlling Image Interpolations

Hacking with Swift / 100 Days / Day-80 - Controlling image interpolation in SwiftUIarrow-up-right

.interpolation(.none) removes the blurriness of the image. It is used on QR Codes especially. Because if used on QR codes it cannat be read properly.

UI Image

#uiimage

CG Image

CI Image

Hacking with Swift / 100 Days / Day-63 - Integrating Core Image with SwiftUIarrow-up-right

Sources

Videos

Hacking with Swift / 100 Days / Day-62 - Integrating Core Image with SwiftUIarrow-up-right

...

Hacking with Swift / 100 Days / Day-63 - Wrapping a UIViewController in a SwiftUI viewarrow-up-right
Hacking with Swift / 100 Days / Day-64 - Using coordinators to manage SwiftUI view controllersarrow-up-right

#PHPickerViewControllerDelegate #NSObject #UIViewControllerRepresentable

Articles / Documents

See Also

Last updated

Was this helpful?