iphone - 在横向和水平 iPhone 位置下使用 ZBarReader 拍照时出现问题

标签 iphone ios ios6 zbar

我正在使用 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/

相关文章:

ios - 提取 JSON 并将其保存在 NSMutableArray 中

ios - 如何在使用另一个 UISwitch 时更新一个 UISwitch

ios - 状态栏在 iOS 6 上消失了

iphone - 在 View 中添加/删除 View 时出现问题

ios - 按下按钮时如何显示事件卡

iphone - iOS 中的消耗品与非消耗品

iphone - iOS 应用程序 - 如何每 60 秒检查一次服务器更新?

ios - 在应用程序的新更新中添加 CoreData 的问题

iphone - iPhone Dev:同时发出短促的声音和振动

jquery - 与移动操作系统兼容的良好 javascript 框架工具包?