UIImagePicker - Do not allow panorama to be picked - ios

Looking for help with an image picker. The picker is functioning properly - however - it allows the user to pick from Panorama photos as well as normal photos on their device.
I want to have the picker only allow the user to choose non panorama pictures.
I looked through the dev document and couldn't find anything about this. Any help appreciated! Here's my code:
#IBAction func selectImage(sender: AnyObject) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType =
UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.mediaTypes = [kUTTypeImage as NSString]
imagePicker.allowsEditing = false
self.clearBtn.hidden = false
self.presentViewController(imagePicker, animated: true,
completion: nil)
}
func imagePickerController(picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
self.dismissViewControllerAnimated(true, completion: nil)
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
self.postImage.contentMode = .ScaleAspectFit
self.postImage.image = image
self.hasPicture = true
}
I know that changing the UIImagePickerControllerSourceType to .PhotoLibrary will only allow picking from the camera roll, but I was hoping to still allow shared photo streams and such that just weren't panoramic.

As Christian posted in a comment - there is no native way for a UIImagePicker to only allow certain types of pictures (excluding panorama).
You have to handle validating the image after it is returned.

Related

How to use "Use video" / "choose" button from video in swift 3?

I'm trying to upload my video chosen from library or recorded from camera to firebase. When I get the video from library there's a "choose" button on the image picker or when I record the video it says "Use video".
I think to run those buttons function you have to write the didFinishPickingMediaWithInfo function. But nothing happens when I record a video and click "choose" this is what I have as my code:
if (UIImagePickerController.isSourceTypeAvailable(.camera)) {
if UIImagePickerController.availableCaptureModes(for: .rear) != nil {
//if the camera is available, and if the rear camera is available, the let the image picker do this
imagePicker.sourceType = .camera
imagePicker.mediaTypes = [kUTTypeMovie as String]
imagePicker.allowsEditing = false
imagePicker.delegate = self as? UIImagePickerControllerDelegate & UINavigationControllerDelegate
imagePicker.videoMaximumDuration = 60
imagePicker.videoQuality = .typeIFrame1280x720
present(imagePicker, animated: true, completion: nil)
} else {
postAlert("Rear camera doesn't exist", message: "Application cannot access the camera.")
}
} else {
postAlert("Camera inaccessable", message: "Application cannot access the camera.")
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
print("didFinishPickingMediaWithInfo")
}
I want it to at least print to know that the video "choose button" is working. Any ideas on how to get the choose button to work? Any help would be kind. Thank you in advance!

iOS - Swift 3 - UIImagePicker avoid "Retake/Use Photo" for multiple photos

I know there are similar questions available on SO.
The reason why I'm starting a new topic.
I want to take multiple photos and save them into an array for later usage (when user finished taking photos)
I already read the API about showsCameraControl, takePicture() and cameraOverlayView
I managed already to capture multiple photos but I have always to confirm every photo with the "Retake/Use Photo" screen. When tipping on Use Photo, the App saves it into the array.
The same way is already working in the Workflow App from DeskConnect. They have a workflow "Take Photo" where you can choose how many photos you want to take. And they are (in my eyes) using Apple's default controls
Any help is appreciated.
Doesn't matter if it's a solution to avoid "Retake/Use Photo" or to create a custom overly view. For me it is important to keep Apple's default controls so the user feels comfortable with the well known controls.
(I also already took a look on the tutorials Apple provides).
My code so far
var imageArray = [UIImage]()
override func viewDidLoad() {
super.viewDidLoad()
openCamera()
}
func openCamera() {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.allowsEditing = false
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
imageArray.append(pickedImage)
print(imageArray.count)
}
self.dismiss(animated: true, completion: nil)
openCamera()
}

cannot Use the "used photo" in IOS swift UIImagePickerController [duplicate]

This question already has answers here:
Swift ImagePickerController didFinishPickingMediaWithInfo not fired
(2 answers)
Closed 6 years ago.
I'm new to swift...
in fact I'm new to Any Apple products. so basically I'm trying to learn how to build and aircraft while trying to fly and learn how to fly it as well. When this disclaimer is out there I'd like some help ;)
My issue is that I cannot get UIImagePickerController to return with an image to me after I've taken one with the Camera. I think I'm missing something fundamental or at least something important to make it work ;)
But I cannot for the life of me figure out where I'm doing it wrong.
this is what I think is the relevant parts of my ViewController however do ask if you feel I'm leaving something important out:
#IBAction func shootPhoto(_ sender: UIButton) {
if UIImagePickerController.isSourceTypeAvailable(.camera) {
picker.allowsEditing = false
picker.sourceType = UIImagePickerControllerSourceType.camera
picker.cameraCaptureMode = .photo
picker.modalPresentationStyle = .fullScreen
present(picker,animated: true,completion: nil)
}
else
{
noCamera()
}
}
private func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let image: UIImage = info[UIImagePickerControllerOriginalImage] as! UIImage;
myImageView.contentMode = .scaleToFill
myImageView.image = image
self.dismiss(animated:true, completion: nil)
}
I must confess I do not know what version of swift I'm using. I'm assuming the latest because I just updated the MacBook Pro until it couldn't do any more. I'm using Xcode 8.2.1 and I'm testing this on a IPhone with IOS 10.2.1 I think it's a IPhone 7s.
Any help is appreciated
Edit:
I'm setting that in this function if that is the wrong place I will move it I just cannot figure out to where. ?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view
picker.delegate = self
}
I'm made aware that this might be a duplicate of another question however when I click to that one they are handling the photo library.
I'm trying to handle the camera and I'm having a issue with returning the image to my imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])...
what they talk about doesn't seem to be working for me and they are using things that I've been told is depricated.
edit 2:
this is how I initialise the picker object as well as how the class is defined
class ViewController: UIViewController,UINavigationControllerDelegate,UIImagePickerControllerDelegate {
let picker = UIImagePickerController()
#IBOutlet weak var myImageView: UIImageView!
private func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
myImageView.image = image
} else if let image = info[UIImagePickerControllerEditedImage] as? UIImage {
myImageView.image = image
}
myImageView.contentMode = .scaleToFill
self.dismiss(animated:true, completion: nil)
}

Generic - Creating an image format with an unknown type is an error - Swift 3

I have an image picker controller. I want to select an image from the photo library and place it in the rounded image view. The image gets placed successfully in the image view but still I get this error "[Generic] Creating an image format with an unknown type is an error".
I have seen many other questions for this but none of them solves my problem. All the questions say that didFinishPickingMediaWithInfo wasn't called but mine is not the case. My image is shown in the image view and I still get the error.
I have set the UIImagePickerControllerDelegate and UINavigationControllerDelegate. Picker is defined as follows:
let picker = UIImagePickerController()
Delegate is set in viewDidLoad as follows:
picker.delegate = self
Photo Library is opened as:
self.picker.allowsEditing = false
self.picker.sourceType = .photoLibrary
self.picker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
self.present(self.picker, animated: true, completion: nil)
My code of didFinishPickingMediaWithInfo is :
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
userImageView.image = image
} else{
print("Something went wrong")
}
self.dismiss(animated: true, completion: nil)
}
I am using xcode 8 and swift 3. Please help.

UIImagePickerController AllowsEditing not working

I am using UIImagePickerController to allow the user to take a picture. I want to allow him/her to edit it afterwards but, whatever I do, I get nothing.
Here is my code (I am using Xamarin):
UIImagePickerController imagePicker = new UIImagePickerController ();
// set our source to the camera
imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
// set what media types
//imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.Camera);
// show the camera controls
imagePicker.ModalPresentationStyle = UIModalPresentationStyle.CurrentContext;
imagePicker.ShowsCameraControls = true;
imagePicker.AllowsEditing = true;
imagePicker.SetEditing (true,true);
imagePicker.PreferredContentSize = new SizeF(900,600);
imagePicker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo;
imagePicker.Title="taste.eat. image";
// attach the delegate
imagePicker.Delegate = new ImagePickerDelegate();
// show the picker
NavigationController.PresentViewController(imagePicker, true,null);
Am I missing something?
EDIT:
I have followed the tutorial and I am getting to the screen with the rectangle, but if i pan or zoom it just snaps back to the center once I lift my finger. Is it possible to get to this screen from the photos application?
When using UIImagePickerController's delegate
method - imagePickerController:didFinishPickingMediaWithInfo:, we get the image using
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
This code will always return the original image, even if editing is ON.
Try using
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
This will return the edited image if editing is ON.
Hope this helps.
The AllowsEditing property simply allows the user to crop to a square if picking an image and trim the video if picking a video.
Any other functionality needs to be implemented with custom UI and code.
See this question:iPhone SDK - How to customize the crop rect in UIImagePickerController with allowsEditing on?
What you are showing in the screenshot is not part of UIImagePickerController, unfortunately
SWIFT 3
I was having a hard time returning the cropped image (simple mistake on my end). Instead of using UIImagePickerControllerOriginalImage, you need UIImagePickerControllerEditedImage. See below:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// The info dictionary contains multiple representations of the image, and this uses the cropped image.
let selectedImage = info[UIImagePickerControllerEditedImage] as! UIImage
// Set yourImageView to display the selected image.
yourImage.image = selectedImage
// Dismiss the picker.
dismiss(animated: true, completion: nil)
}
SWIFT 4+
There have been some changes after Swift 4. UIImagePickerControllerEditedImage changed to UIImagePickerController.InfoKey.editedImage.
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let selectedImage = info[UIImagePickerController.InfoKey.editedImage] as! UIImage
imageView.image = selectedImage
dismiss(animated: true, completion: nil)
}
It will be work like this way.
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let selectedImage = info[UIImagePickerControllerEditedImage] as! UIImage
userPhoto.image = selectedImage
dismiss(animated: true, completion: nil)
}
There is no way to enable filters by just changing property like allowsEditing = YES. It will only display a cropping tool. As per your screenshot it's look like you have integrated some buggy open source library and without looking at the source code it would be difficult to fix your center cropping bug.
Better to post some concrete detail about your implementation or switch to standard open source library.

Resources