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 PHPickerViewController

Filtering Image

#CIFilterBuiltins

Hacking with Swift / 100 Days / Day-65 - Basic image filtering using Core Image

Saving Images

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

#uiimagewritetosavedphotosalbum #saveimage

Controlling Image Interpolations

Hacking with Swift / 100 Days / Day-80 - Controlling image interpolation in SwiftUI

.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 SwiftUI

Sources

Videos

Hacking with Swift / 100 Days / Day-62 - Integrating Core Image with SwiftUI

...

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

#PHPickerViewControllerDelegate #NSObject #UIViewControllerRepresentable

Articles / Documents

See Also

Last updated