UIImagePickerController返回错误的图像方向 [英] UIImagePickerController returning incorrect image orientation

查看:164
本文介绍了UIImagePickerController返回错误的图像方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UIImagePickerController捕获图像,然后将其存储.但是,当我尝试重新缩放比例时,我从该图像中获得的方向值不正确.当我按住手机向上按一下时,它使我朝左方向.有人遇到过这个问题吗?

I'm using UIImagePickerController to capture an image and then store it. However, when i try to rescale it, the orientation value i get out of this image is incorrect. When i take a snap by holding the phone Up, it gives me orientation of Left. Has anyone experienced this issue?

UIImagePickerController词典显示以下信息:

The UIImagePickerController dictionary shows following information:

{
    UIImagePickerControllerMediaMetadata =     {
        DPIHeight = 72;
        DPIWidth = 72;
        Orientation = 3;
        "{Exif}" =         {
            ApertureValue = "2.970853654340484";
            ColorSpace = 1;
            DateTimeDigitized = "2011:02:14 10:26:17";
            DateTimeOriginal = "2011:02:14 10:26:17";
            ExposureMode = 0;
            ExposureProgram = 2;
            ExposureTime = "0.06666666666666667";
            FNumber = "2.8";
            Flash = 32;
            FocalLength = "3.85";
            ISOSpeedRatings =             (
                125
            );
            MeteringMode = 1;
            PixelXDimension = 2048;
            PixelYDimension = 1536;
            SceneType = 1;
            SensingMethod = 2;
            Sharpness = 1;
            ShutterSpeedValue = "3.910431673351467";
            SubjectArea =             (
                1023,
                767,
                614,
                614
            );
            WhiteBalance = 0;
        };
        "{TIFF}" =         {
            DateTime = "2011:02:14 10:26:17";
            Make = Apple;
            Model = "iPhone 3GS";
            Software = "4.2.1";
            XResolution = 72;
            YResolution = 72;
        };
    };
    UIImagePickerControllerMediaType = "public.image";
    UIImagePickerControllerOriginalImage = "<UIImage: 0x40efb50>";
}

但是图片返回imageOrientation == 1;

UIImage *picture = [info objectForKey:UIImagePickerControllerOriginalImage];             

推荐答案

我刚刚开始在自己的应用程序中解决此问题.

I just started working on this issue in my own app.

我使用了Trevor Harmon精心设计的UIImage类别来调整图像大小并固定其方向,

I used the UIImage category that Trevor Harmon crafted for resizing an image and fixing its orientation, UIImage+Resize.

然后您可以在-imagePickerController:didFinishPickingMediaWithInfo:


UIImage *pickedImage = [info objectForKey:UIImagePickerControllerEditedImage];
UIImage *resized = [pickedImage resizedImageWithContentMode:UIViewContentModeScaleAspectFit bounds:pickedImage.size interpolationQuality:kCGInterpolationHigh];

这为我解决了这个问题.调整大小后的图像在视觉上正确定向,并且imageOrientation属性报告UIImageOrientationUp.

This fixed the problem for me. The resized image is oriented correctly visually and the imageOrientation property reports UIImageOrientationUp.

此缩放/调整大小/裁剪代码有多个版本;我使用Trevor是因为它看起来很干净,并且包含其他一些我稍后要使用的UIImage操纵器.

There are several versions of this scale/resize/crop code out there; I used Trevor's because it seems pretty clean and includes some other UIImage manipulators that I want to use later.

这篇关于UIImagePickerController返回错误的图像方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆