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
                }
            }
        }
    }
}

Filtering Image

#CIFilterBuiltins

Saving Images

Hacking with Swift / 100 Days / Day-64 - How to save images to the user’s photo library

#uiimagewritetosavedphotosalbum #saveimage

Controlling Image Interpolations

.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

Sources

Videos

...

#PHPickerViewControllerDelegate #NSObject #UIViewControllerRepresentable

Articles / Documents

See Also

Last updated