Domanda

I use the following code to check but it doesn't work.. always returns portrait even on images taken in landscape

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

    //dismiss imagepicker controller
    [self dismissViewControllerAnimated:NO completion:nil];

    fishingSpotChosenImage = [info objectForKey:UIImagePickerControllerOriginalImage];

    if (fishingSpotChosenImage.imageOrientation == UIImageOrientationUp) {
        NSLog(@"portrait");
    } else if (fishingSpotChosenImage.imageOrientation == UIImageOrientationLeft || fishingSpotChosenImage.imageOrientation == UIImageOrientationRight) {
        NSLog(@"landscape");
    }
  }

Im assuming it doesn't work because the image is actually in portrait when selected so how do I detect when the image has black bars like the following image..enter image description here

È stato utile?

Soluzione

Yeah, in this case your "landscape" image orientation is still "UP" since the image is right-side up.

If you only care about images that are of the camera's 4:3 or 3:4 rectangular aspect ratio, perhaps you can just compare the image width to the image height to see whether it's wider than it is tall or vice versa using UIImage's size property, ex.

if (fishingSpotChosenImage.size.height > fishingSpotChosenImage.size.width) {
    NSLog(@"portrait");
} else {
    NSLog(@"landscape");
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top