2

How to check, the image selected from UIImagePickerController is a Panorama Image or not?

Raptor
  • 53,206
  • 45
  • 230
  • 366
Anand
  • 2,086
  • 2
  • 26
  • 44

2 Answers2

1

In this UIImagePickerController delegate method (be sure to add delegate methods to your View Controller class):

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  [self dismissViewControllerAnimated:YES completion:NULL];
  UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];   

  // determine if it's panorama by checking its dimension
  CGFloat imageWidth = image.size.width;
  CGFloat imageHeight = image.size.height;

  // display the image if needed
  [self.imageView setImage:image];

  self.imagePickerController = nil;
}

Theoretically panorama images have much longer width than normal image. But this can't check if it is a web image downloaded from elsewhere.

Raptor
  • 53,206
  • 45
  • 230
  • 366
  • this doesn't help,I tried it because you can have same size of images downloaded from websites also & saved it on album . – Anand Feb 13 '14 at 03:22
  • 1
    Yes, I mentioned it in the answer. You can check the EXIF to check whether it's taken by iPhone. This [answer](http://stackoverflow.com/questions/9766394/get-exif-data-from-uiimage-uiimagepickercontroller) may guide you to do so. – Raptor Feb 13 '14 at 03:27
0

Swift 3.0

As per above suggestion we can check panorama images are more in width so we can ignore large width images

Normal Image info " size {960, 960} orientation 1 scale 1.000000"

Panorama Image Info " size {13632, 2936} orientation 1 scale 1.000000"

let str = "\(info["UIImagePickerControllerOriginalImage"]!)"

   let s = str.slice(from: "{", to: "}")

    if let arr = s?.components(separatedBy: ","){
        if arr.count >= 2 {
            if Int(arr[0])! > 11000 {
                picker.dismiss(animated:true, completion: nil)
                self.makeToast("Invalid Image!!!")
                return
            }

            if Int(arr[1])! > 11000 {
                 picker.dismiss(animated:true, completion: nil)
                self.makeToast("Invalid Image!!!")
                return
            }
        }
 }
krish
  • 3,856
  • 2
  • 24
  • 28