如何使用ALAsset获得图像的裁剪版本? [英] How do you get the cropped version of an image using ALAsset?

查看:102
本文介绍了如何使用ALAsset获得图像的裁剪版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ALAsset获取图像的裁剪版本。具体来说,我正在从用户的照片库中选择项目,然后上传它们。问题是在库缩略图视图中,iOS向我们显示了裁剪版本。当您选择该缩略图并使用ALAsset拉取该图像的资源时,我会获得完整的分辨率版本。
我做了一些研究,找不到任何有助于获得裁剪发生位置的第二个坐标系的东西。

I'm trying to get the cropped version of an image that's pulled using ALAsset. Specifically, I'm selecting items from the user's Photo Library and then uploading them. The issue is that in the library thumbnail view, iOS is showing us the cropped version. When you select that thumbnail and pull that image's asset using ALAsset, I get the full resolution version. I did some research and couldn't find anything that helps in getting a second coordinate system of where the cropping happens.

要测试它,你需要iOS5编辑库中的图像。在图像库中选择图像,选择编辑,然后裁剪图像。当您获得ALAsset时,您将获得完整的图像,如果您使用iPhoto进行同步,iPhoto也会获取完整的图像。此外,您可以重新编辑图像并撤消裁剪。

To test it, you need iOS5 to edit the image in your library. Select an image in your image library, select "Edit", and crop the image. When you get the ALAsset you'll get the full image, and if you sync using iPhoto, iPhoto also pulls the full image. Also, you can re-edit the image and undo your crop.

这就是我获取图像的方式:

This is how I'm getting the image:

UIImage *tmpImage = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];

显然,这给了我全分辨率图像。有一个fullScreenImage标志,可以将全分辨率图像缩放到屏幕大小。这不是我想要的。

That gives me the full resolution image, obviously. There's a fullScreenImage flag which scales the full resolution image to the size of the screen. That's not what I want.

ALAssetRepresenation类有一个scale字段,但这是一个浮点值,这也是我不想要的。

The ALAssetRepresenation class has a scale field, but that's a float value, which is also what I don't want.

如果有人能告诉我这个裁剪坐标系的位置,我会很感激。

If anyone can tell me where this cropped coordinate system can be found, I'd appreciate it.

推荐答案

使用iOS Photos App裁剪照片时,可以在ALAssetRepresentation的元数据字典中找到裁剪坐标。 fullResolutionImage将为您提供未剪切的照片,您必须自己进行裁剪。

When a photo has been cropped with the iOS Photos App, the cropping coordinates can be found in the ALAssetRepresentation's metadata dictionary. fullResolutionImage will give you the uncropped photo, you have to perform the cropping yourself.

AdjustmentXMP元数据不仅包含裁剪坐标,还指示是否自动增强或删除 - 已经应用了红眼。

The AdjustmentXMP metadata contains not only the cropping coordinates but also indicates if auto-enhance or remove-red-eyes has been applied.

从iOS 6.0开始,CIFilter提供了filterArrayFromSerializedXMP:inputImageExtent:错误:可能你可以在这里使用ALAssetRepresentation的AdjustmentXMP元数据并将CIFilter应用到ALAssetRepresentation的fullResolutionImage用于重新创建修改后的图像。

As of iOS 6.0 CIFilter provides filterArrayFromSerializedXMP:inputImageExtent:error: Probably you can use the ALAssetRepresentation's AdjustmentXMP metadata here and apply the CIFilter onto the ALAssetRepresentation's fullResolutionImage to recreate the modified image.

请注意,iOS照片应用程序处理JPG和RAW图像的方式不同。对于JPG图像,带有XMP元数据的新ALAsset存储在相机胶卷中。对于RAW图像,ALAssetRepresentation被添加到原始ALAsset。我不确定这个额外的ALAssetRepresentation是否是修改后的图像,是否具有AdjustmentXMP元数据。除了JPG和RAW图像,您还应该测试RAW + JPG图像的行为。

Be aware that the iOS Photos App handles JPG and RAW images differently. For JPG images a new ALAsset with the XMP metadata is stored in the Camera Roll. For RAW images an ALAssetRepresentation is added to the original ALAsset. I'm not sure if this additional ALAssetRepresentation is the modified image and if it has the AdjustmentXMP metadata. In addition to JPG and RAW images you should also test the behaviour for RAW+JPG images.

这篇关于如何使用ALAsset获得图像的裁剪版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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