Skip to content

Instantly share code, notes, and snippets.

@SlappyAUS
Last active October 17, 2020 09:11
Show Gist options
  • Select an option

  • Save SlappyAUS/6a0203dbd537c7cc1e81492ef0dbaf8c to your computer and use it in GitHub Desktop.

Select an option

Save SlappyAUS/6a0203dbd537c7cc1e81492ef0dbaf8c to your computer and use it in GitHub Desktop.
Camera and photo selector #ui
//
// ViewController.swift
// WhatFlower
//
// Created by Greg Eales on 17/10/20.
//
import UIKit
// TODDO: Add to .plist
// Privacy: Camera Usage Description
// Privacy: Photo Library Usage Description
class ViewController: UIViewController {
@IBOutlet weak var selectedImage: UIImageView!
let imagePicker = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
// if true, then use info[UIImagePickerControllerEditedImage] in didFinishPickingMediaWithInfo
imagePicker.allowsEditing = false
navigationController?.delegate = self
}
@IBAction func barButtonPressed(_ sender: UIBarButtonItem) {
if sender.tag == 0 {
// File picker
imagePicker.sourceType = .photoLibrary
} else {
// Camera
imagePicker.sourceType = .camera
}
present(imagePicker, animated: true, completion: nil)
}
func detectImage(image: CIImage) {
}
}
// MARK: - UIImagePickerControllerDelegate
extension ViewController: UIImagePickerControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let userImage = info[.originalImage] as? UIImage {
selectedImage.image = userImage
guard let ciImage = CIImage(image: userImage) else {
fatalError("Could not convert image to CI Image")
}
detectImage(image: ciImage)
}
imagePicker.dismiss(animated: true, completion: nil)
}
}
// MARK: - UINavigationControllerDelegate
extension ViewController: UINavigationControllerDelegate {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment