如何正确裁剪 iPhone 4G 拍摄的图像(带有 EXIF 旋转数据)?

发布于 2024-12-01 16:38:30 字数 731 浏览 0 评论 0 原文

各位,

我一直在尝试让此代码处理 iPhone 4G 上相机拍摄的图像,但没有成功:

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

此代码非常适合裁剪“正常”图像 - 我从互联网或我的 iPhone 3G 拍摄的图像。

调用旋转代码后,iPhone 4G 相机的照片似乎会被完全随机地裁剪到图像的部分。

我什至尝试使用这段代码: 调整从相机拉出的 UIimage 的大小也会旋转 UIimage?< /a>

我将图像“调整”到与它具有的尺寸相同的尺寸以实现旋转,然后尝试在不考虑旋转的情况下裁剪图像。也没有运气。

有什么方法可以拍摄 iPhone 4G 相机拍摄的图像并将其转换为与从互联网下载的图像具有相同质量/属性的图像(即没有旋转信息和/或其像素被旋转)从一开始就正确),以便我尝试执行的后续操作(在本例中是裁剪)将按我的预期进行?

谢谢!

Folks,

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

iPhone - CGImageCreateWithImageInRect rotating some camera roll pictures

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 camera photos appear to be getting cropped in totally random parts of the image after when that rotation code is called.

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.

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?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人心善变 2024-12-08 16:38:30

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

使用具有 EXIF 旋转信息的图像裁剪区域的正确方法是使用 这家伙的代码,但不要使用这一行:

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

您应该调用此:

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

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

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

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.

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];

You should call this:

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文