Appygix
Appygix

Reputation: 652

UIImagePickerController - Choose saved images in the camera view

I am able to start the UIImagePickerController to make a picture:

func selectCamera(){
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
        let imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.Camera;
        imagePicker.allowsEditing = true
        self.presentViewController(imagePicker, animated: true, completion: nil)
    }
}

and with this function to choose from the saved pictures:

func selectPicture() {
    let picker = UIImagePickerController()
    picker.allowsEditing = true
    picker.delegate = self
    presentViewController(picker, animated: true, completion: nil)
}

I can either choose a image from my image gallery on the phone or take a picture.

But i want to choose one of the saved image gallery pics inside the camera view, how it is in the standard camera application. Is this possible?

Upvotes: 4

Views: 1627

Answers (2)

Igor Kuznetsov
Igor Kuznetsov

Reputation: 108

I am using this solution, without additional libraries. First of all don't forget to delegate, UIImagePickerControllerDelegate, and navigation delegate. Those thigns needed only for imagePickerController.

Update, check function saveImageViewToAlbum, be sure that your imageView containt image, otherwise you probably will catch exception. Adds a photo to the saved photos album. The optional completionSelector should have the form:

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo;

Just created this project, and everything works on swift, iOS 9.3

    import UIKit

    class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    @IBOutlet weak var choosenImageView: UIImageView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func openAlbum(sender: UIButton) {
        let imagePickerController = UIImagePickerController()
        imagePickerController.delegate = self
        imagePickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
        self .presentViewController(imagePickerController, animated: true, completion: nil)

    }
    func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {

        choosenImageView.image = image
        self .dismissViewControllerAnimated(true, completion: nil)
    } 
@IBAction func saveImageViewToAlbum(sender: UIButton) {
                UIImageWriteToSavedPhotosAlbum(choosenImageView.image!, nil, nil, nil)
    }
}

Upvotes: -1

Kakshil Shah
Kakshil Shah

Reputation: 3796

If you want to have Gallery Pics inside camera view, you got to create a custom cameraOverlay view, which has a button to then open the saved pictures.

To make it faster, you can use a library like --> https://github.com/GabrielAlva/Cool-iOS-Camera

Or

You can also have a action sheet, asking user to select which option he wants.

Check this -> How to allow the user to pick a photo from his camera roll or photo library? & this --> https://github.com/chroman/CRMediaPickerController

Upvotes: 3

Related Questions