Questions tagged [uiimagepickercontroller]

Questions related to the iOS UIImagePickerController class (and the associated UIImagePickerControllerDelegate protocol), which provides system-supplied user interfaces for taking pictures and movies on iOS devices, and for choosing saved images and movies.

The UIImagePickerController class manages customizable, system-supplied user interfaces for taking pictures and movies on supported devices, and for choosing saved images and movies for use in your app. An image picker controller manages user interactions and delivers the results of those interactions to a delegate object.

The role and appearance of an image picker controller depend on the source type you assign to it before you present it.

  • A sourceType of UIImagePickerControllerSourceTypeCamera provides a user interface for taking a new picture or movie (on devices that support media capture).
  • A sourceType of UIImagePickerControllerSourceTypePhotoLibrary or
    UIImagePickerControllerSourceTypeSavedPhotosAlbum provides a user
    interface for choosing among saved pictures and movies.

To use an image picker controller containing its default controls, perform these steps:

  1. Verify that the device is capable of picking content from the desired source. Do this calling the isSourceTypeAvailable: class method, providing a constant from the “UIImagePickerControllerSourceType” enum.
  2. Check which media types are available, for the source type you’re using, by calling the availableMediaTypesForSourceType: class method. This lets you distinguish between a camera that can be used for video recording and one that can be used only for still images.
  3. Tell the image picker controller to adjust the UI according to the media types you want to make available—still images, movies, or both—by setting the mediaTypes property.
  4. Present the user interface by calling the presentViewController:animated:completion: method of the currently active view controller, passing your configured image picker controller as the new view controller. On iPad, present the user interface using a popover. Doing so is valid only if the sourceType property of the image picker controller is set to UIImagePickerControllerSourceTypeCamera. To use a popover controller, use the methods described in “Presenting and Dismissing the Popover” in UIPopoverController Class Reference.
  5. When the user taps a button to pick a newly-captured or saved image or movie, or cancels the operation, dismiss the image picker using your delegate object. For newly-captured media, your delegate can then save it to the Camera Roll on the device. For previously-saved media, your delegate can then use the image data according to the purpose of your app.

    For details on these steps, refer to Apple's “Taking Pictures and Movies”.

4123 questions
52
votes
9 answers

How to make UIImagePickerController for camera and photo library at the same time in swift

I use UIImagePickerController to take a photo by camera of iPhone. I want to show both "take a photo" and "choose a photo". My code imagePicker = UIImagePickerController() imagePicker.delegate = self imagePicker.sourceType =…
Coucou
  • 645
  • 1
  • 6
  • 9
52
votes
14 answers

How to get image file size in Swift?

I am using UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIPopoverControllerDelegate these delegates for choosing image from my gallery or my camera. So, how can I get image file size after choosing an image? I want to use…
Orkhan Alizade
  • 7,379
  • 14
  • 40
  • 79
49
votes
6 answers

Swift - UIImagePickerController - how to use it?

I am trying hard to understand how this works, but it's pretty hard for me. =) I have 1 view, there is one button and one small ImageView area for preview. The button triggers imagepickercontroller, and the UIView will display picked image. There is…
user3806731
  • 889
  • 2
  • 8
  • 14
47
votes
8 answers

UIImagePicker allowsEditing stuck in center

I have a UIImagePicker that works perfect for a type of UIImagePickerControllerSourceTypePhotoLibrary, but when I use UIImagePickerControllerSourceTypeCamera, the editing box cannot move from the center of the image. So if the image is say taller…
Eric
  • 5,671
  • 5
  • 31
  • 42
45
votes
9 answers

How to open the ImagePicker in SwiftUI?

I need to open an image picker in my app using SwiftUI, how can I do that? I thought about using the UIImagePickerController, but I don't know how to do that in SwiftUI.
Shahar Melamed
  • 1,534
  • 5
  • 15
  • 23
43
votes
3 answers

iPhone: Camera Preview Overlay

How do I add an overlay (UIImageView) to the camera preview and handle touches on this? My previous attempts to do this (e.g. use UIImagePickerController and add the image as a subview) have failed.
Stefan
  • 28,843
  • 15
  • 64
  • 76
41
votes
3 answers

What's the difference between Camera Roll and Photo Library?

UIImagePickerController has these source type constants: UIImagePickerControllerSourceTypePhotoLibrary UIImagePickerControllerSourceTypeSavedPhotosAlbum The documentation says one is for the photo library while the other is for the camera roll.…
openfrog
  • 40,201
  • 65
  • 225
  • 373
41
votes
2 answers

Saving Picked Image to CoreData

I am able to pick and display an image from the photo library, but my goal is to be able to save that picked image or file path to core data so that when that saved record is chosen that image will display also. I have CoreData working and I am able…
turtle02
  • 603
  • 3
  • 10
  • 17
40
votes
4 answers

Camera with Custom View

My Application uses camera, I would like to add overlay over the camera preview. For example, I want to use a picture frame when I use Camera, also I would like to add a custom bar for camera operations. Kindly help me to do the same.
cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241
39
votes
4 answers

Set dimensions for UIImagePickerController "move and scale" cropbox

How does the "move and scale screen" determine dimensions for its cropbox? Basically I would like to set a fixed width and height for the "CropRect" and let the user move and scale his image to fit in to that box as desired. Does anyone know how to…
Thomas K
  • 6,076
  • 5
  • 39
  • 56
39
votes
1 answer

When should I use UIImagePickerControllerSourceTypePhotoLibrary instead of UIImagePickerControllerSourceTypeSavedPhotosAlbum?

I have an application that allows the user to pick a photo from their device. To do this, I'm using the UIImagePickerController, but the problem is that I'm unsure whether I should be using a source type of…
Micah Hainline
  • 14,367
  • 9
  • 52
  • 85
39
votes
2 answers

Setting delegate for UIImagePicker returns error

Having a problem in some swift code I had written for an OCR translation app. The code snippet is below: @IBAction func btnOCR(sender: AnyObject) { var languageAlert = UIAlertController(title: "For Your Information...", message: "The OCR…
Jacob King
  • 6,025
  • 4
  • 27
  • 45
38
votes
8 answers

Presenting a modal view controller immediately after dismissing another

I'm dismissing a modal view controller and then immediately presenting another one, but the latter never happens. Here's the code: [self dismissModalViewControllerAnimated:YES]; UIImagePickerController *picker = [[UIImagePickerController alloc]…
James Skidmore
  • 49,340
  • 32
  • 108
  • 136
38
votes
12 answers

UIImagePickerController camera view rotating strangely on iOS 8 (pictures)

I have a very simple application: - All orientations are permitted with only a button on a screen - The button show a UIImagePickerController (to take a photo) - Build with Xcode 5 and SDK 7 On iOS 8, the camera of the UIImagePickerController is…
37
votes
1 answer

UIImagePickerController - How do I access the front facing camera by default?

I am bringing up the camera with the following code from my ViewController: - (void)viewDidLoad { self.imgPicker = [[UIImagePickerController alloc] init]; self.imgPicker.sourceType = UIImagePickerControllerCameraDeviceFront; …
Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195