我正在使用 ZBar 来检测代码,但我也想启用从同一屏幕拍照。我发现横向拍照时有一种奇怪的行为。如果我将手机置于垂直横向位置,则图像显示正常,但如果我将 iPhone 移至平面横向位置,则图像显示为上下颠倒。我检查了 UIImage 元数据,图像方向具有不同的值,尽管设备方向在两种情况下是相同的。
知道为什么会发生这种情况吗?
最佳答案
我的解决方案是在错误的情况下更改图像方向元数据:
-(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];
}
}
}
}
关于iphone - 在横向和水平 iPhone 位置下使用 ZBarReader 拍照时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18634752/