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

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

问题描述

伙计们,

我试图让这段代码处理 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 大小也会旋转 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 相机上拍摄的图像并将其转换为与从 Internet 下载的图像具有相同质量/属性的图像(即,没有旋转信息和/或其像素从一开始就正确旋转),以便我尝试执行的后续操作(在本例中为裁剪)将按预期工作?

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?

谢谢!

推荐答案

有一个很多 示例 代码 out 在网上为此.对于 iPhone 4G,这一切都是不完整或错误的,因为 iPhone 4G 将旋转 EXIF 数据嵌入到其 JPEG 文件中.此数据通过 iOS 4 中新增的 imageOrientation 属性公开.

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天全站免登陆