使用ZBarReader在横向和iPhone平面位置拍照的问题

时间:2013-09-05 11:09:24

标签: iphone ios ios6 zbar

我正在使用ZBar来检测代码,但是,我想启用从同一屏幕拍摄照片。我发现了以横向拍摄照片的奇怪行为。如果我将手机置于垂直横向位置,图像就可以正常显示,但是如果我将iPhone移动到平坦的横向位置,图像就会颠倒过来。我检查了UIImage元数据,并且图像方向具有不同的值,尽管在两种情况下设备方向都相同。

知道为什么会这样吗?

1 个答案:

答案 0 :(得分:1)

我的解决方案是在错误的情况下更改图像方向元数据:

-(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];
            }
        }
    }

}