Question

I'm using ZBar to detect codes but also, I want to enable taking pictures from the same screen. I detected an odd behaviour taking pictures in landscape orientation. If I put my mobile in vertical landscape position the image comes out ok, but If I move my iPhone to the flat landscape position, the picture comes out upside down. I checked UIImage metadata and the image orientation has different values, despite the fact that the device orientation is the same in both cases.

Any idea why this happens?

Was it helpful?

Solution

My solution is to change the image orientation metadata in the wrong cases:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[....]
            UIImage *image = [info objectForKey: UIImagePickerControllerOriginalImage];
            if(image){
                // This fixes a bug in ZBarReader taking picture in landscape orientation and device in flat position.
                NSLog(@"Image: %d, Device: %d",image.imageOrientation,self.interfaceOrientation);
                UIImageOrientation imgOrientation = image.imageOrientation;
                UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;
                if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft && imgOrientation == UIImageOrientationUp){
                    image = [UIImage imageWithCGImage:[image CGImage] scale:1.0 orientation:UIImageOrientationDown];
                }else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight && imgOrientation == UIImageOrientationDown){
                    image = [UIImage imageWithCGImage:[image CGImage] scale:1.0 orientation:UIImageOrientationUp];
                }
                [self hideScanner];
                [self performSegueWithIdentifier:@"mySegue" sender:image];
            }
        }
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top