如何正确裁剪iPhone 4G拍摄的图像(使用EXIF旋转数据)? [英] How to properly crop an image taken on iPhone 4G (with EXIF rotation data)?

查看:175
本文介绍了如何正确裁剪iPhone 4G拍摄的图像(使用EXIF旋转数据)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Folks,

我未能成功尝试取得此代码,以处理由iPhone 4G上的相机拍摄的图片:

I have been unsuccessfully trying to get this code to work with images taken by the camera on an iPhone 4G:

iPhone - CGImageCreateWithImageInRect旋转了一些相机胶卷图片

此代码适用于裁剪正常图片 - 我已从互联网上下载的图片或由我的iPhone 3G拍摄的图片。

This code works great for cropping "normal" images - images I have downloaded off of the internet or images that were taken by my iPhone 3G.

当调用该旋转代码时,iPhone 4G相机照片在图片的完全随机部分中被裁剪。

iPhone 4G camera photos appear to be getting cropped in totally random parts of the image after when that rotation code is called.

我甚至尝试使用这个代码:
调整从相机拉取的UIimages也会ROTATES UIimage?

I even tried using this code: Resizing UIimages pulled from the Camera also ROTATES the UIimage?

并且我将图像调整为与为了实现相同的尺寸旋转,然后尝试裁剪图像而不考虑旋转。也没有运气。

And I "resized" the image to the same dimensions it had in order to achieve the rotation, then attempted to crop the image without taking rotation into account. No luck either.

有没有办法我可以拍摄在iPhone 4G相机拍摄的图像,并将其转换为具有相同的质量/属性的图像图像(即,没有旋转信息和/或其像素从一开始就被正确地旋转),使得我试图执行的后续操作(在这种情况下为裁剪)将如我期望的那样工作。

Is there any way I can take an image captured on the iPhone 4G camera and convert it into an image that has the same qualities/properties as an image downloaded off of the internet (ie, has no rotation information and/or its pixels are rotated properly from the outset), so that subsequent operations I attempt to perform (in this case cropping) will work as I expect?

谢谢!

推荐答案

有一个很多 示例 代码 在网上为此。它是所有不完全或错误,当谈到iPhone 4G,因为iPhone 4G嵌入旋转EXIF数据到其JPEG。此数据通过imageOrientation属性(iOS中新增的)显示。

There is a lot of sample code out on the web for this. It's all incomplete or wrong when it comes to iPhone 4G, because iPhone 4G embeds rotation EXIF data into its JPEGs. This data is exposed via the imageOrientation property, new in iOS 4.

使用具有EXIF旋转信息的图像裁剪区域的正确方法是使用这个花花公子的代码,而不是使用这行:

The correct way to crop a region with images that have EXIF rotation information is to use this dude's code, but instead of using this line:

UIImage *resultImage = [[[UIImage alloc] initWithCGImage:resultImageRef] autorelease];

您应该叫这个:

UIImage *resultImage = [[[UIImage alloc] initWithCGImage:resultImageRef scale:1.0 orientation:originalImage.imageOrientation] autorelease];

第二个调用将旋转信息从原始图像嵌入UIImage。

The second call embeds rotation information into the UIImage from the original image.

不幸的是,该呼叫不适用于iOS 3.XX;幸运的是,您不可能在这些设备上遇到带有EXIF信息的图像,因为相机无法使用旋转信息拍摄照片。

Unfortunately that call isn't available on iOS 3.XX; fortunately it is unlikely that you will encounter images with EXIF information on those devices because the camera's can't take photos with rotation information.

这篇关于如何正确裁剪iPhone 4G拍摄的图像(使用EXIF旋转数据)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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