Last active
October 17, 2020 09:11
-
-
Save SlappyAUS/6a0203dbd537c7cc1e81492ef0dbaf8c to your computer and use it in GitHub Desktop.
Camera and photo selector #ui
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // 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