ALAsset 中的照片方向行为不正确
我当前有一个使用 ALAsssetsLibrary 来获取照片的应用程序。我已将照片放置到图像视图中,并且可以上传到服务器。拍了几张照片后在真机上测试时,发现原本应该拍人像的照片变成了风景。
因此,我调用了不同的函数来获取 CGImage,如下所示:
UIImage *image = [UIImage imageWithCGImage:[representation fullResolutionImage] scale:1.0 orientation:(UIImageOrientation)[representation orientation]];
第一次尝试,我使用了这个:
UIImage *image = [UIImage imageWithCGImage:[representation fullResolutionImage]]
我认为具有比例和方向的函数可以为我提供拍摄照片的正确方向。但它没有给我正确的解决方案。
我是否错过了生成正确照片方向所需的任何内容?
I current have an app that uses ALAsssetsLibrary to fetch the photos. I have placed the photo to an image view and I am able to upload to the server. When I tested on the real device after taking some photos, I found out the photos that supposed to be taken in Portrait become a landscape.
Therefore, I called different function to get the CGImage like this:
UIImage *image = [UIImage imageWithCGImage:[representation fullResolutionImage] scale:1.0 orientation:(UIImageOrientation)[representation orientation]];
The first tried out, I used this :
UIImage *image = [UIImage imageWithCGImage:[representation fullResolutionImage]]
I thought the one with scale and orientation could give me the right orientation that the photo was taken. But it didn't give me the right solution.
Do I miss anything that is necessary to generate a correct orientation of photo?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正确的方向处理取决于您使用的 iOS 版本。
在 iOS4 和 iOS 5 上,缩略图已经正确旋转,因此您可以在不指定任何旋转参数的情况下初始化 UIImage。
但是,对于 fullScreenImage,每个 iOS 版本的行为都不同。在 iOS 5 上,图像已经旋转,但在 iOS 4 上则不然。
因此,在 iOS4 上,您应该使用:
在 iOS5 上,以下代码应该可以正常工作:
干杯,
Hendrik
The correct orientation handling depends on the iOS version you are using.
On iOS4 and iOS 5 the thumbnail is already correctly rotated, so you can initialize your UIImage without specifying any rotation parameters.
However for the fullScreenImage, the behavior is different for each iOS version. On iOS 5 the image is already rotated on iOS 4 not.
So on iOS4 you should use:
On iOS5 the following code should work correctly:
Cheers,
Hendrik
试试这个代码:-
这可能对你有帮助。
Try this code:-
This may help you.
我的经验仅限于 IOS 5.x,但我可以告诉你缩略图和全屏图像的方向正确。这是垂直拍摄时水平的全分辨率图像。我的解决方案是使用我从这里获得的 uiimage 上的类别:
http://www.catamount.com/forums/viewtopic.php?f=21&t=967&start=0
它在 UIImage 上提供了一个很好的旋转方法 像这样:
My experience is limited to IOS 5.x but I can tell you that the thumbnail and fullscreen images are oriented properly. It's the fullresolutionimage that's horizontal when shot vertically. My solution is to use a category on uiimage that I got from here:
http://www.catamount.com/forums/viewtopic.php?f=21&t=967&start=0
It provides a nice rotating method on a UIImage like this:
对于
fullResolutionImage
,我想提供如下解决方案,imageData
就是你想要的,只需将其上传到你的照片服务器即可。顺便说一句,如果您认为 EXIF 有用,您可以根据需要将其补充到
normalizedImage
中。For
fullResolutionImage
, I'd like to provide a solution as follows,imageData
is what you want, and just upload it to your photo server.By the way, if you think EXIF is useful, you can complement it to
normalizedImage
as you wish.