ios - 从 ALAssetRepresentation 获取 "retouched"图像

标签 ios objective-c uiimage alassetslibrary

给定一个 ALAssetRepresentation,是否有可能得到它的全分辨率修饰图像?

如果我使用 fullResolutionImage 方法,我会得到全分辨率图像,但未以任何方式调整。

如果我使用 fullScreenImage 方法,我会得到修饰后的图像,但缩小到适合全屏显示

最佳答案

这并不容易,但你可以。请注意,这还将应用用户在 Photos.app 中完成的任何裁剪:

ALAssetRepresentation *representation = asset.defaultRepresentation;
CGImageRef fullResolutionImage = CGImageRetain(representation.fullResolutionImage);
// AdjustmentXMP constains the Extensible Metadata Platform XML of the photo
// This XML describe the transformation done to the image.
// http://en.wikipedia.org/wiki/Extensible_Metadata_Platform
// Have in mind that the key is not exactly documented.
NSString *adjustmentXMP = [representation.metadata objectForKey:@"AdjustmentXMP"];

NSData *adjustmentXMPData = [adjustmentXMP dataUsingEncoding:NSUTF8StringEncoding];
NSError *__autoreleasing error = nil;
CGRect extend = CGRectZero;
extend.size = representation.dimensions;
NSArray *filters = [CIFilter filterArrayFromSerializedXMP:adjustmentXMPData inputImageExtent:extend error:&error];
if (filters)
{
  CIImage *image = [CIImage imageWithCGImage:fullResolutionImage];
  CIContext *context = [CIContext contextWithOptions:nil];
  for (CIFilter *filter in filters)
  {
    [filter setValue:image forKey:kCIInputImageKey];
    image = [filter outputImage];
  }

  CGImageRelease(fullResolutionImage);
  fullResolutionImage = [context createCGImage:image fromRect:image.extent];
}

// At this moment fullResolutionImage will be the filtered image, or the full
// resolution one if no filters were applied.
// You will need to CGImageRelease fullResolutionImage after you have finished
// working with it.

关于ios - 从 ALAssetRepresentation 获取 "retouched"图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18086093/

相关文章:

ios - viewForHeaderInSection 在 UITableView 中只被调用一次

iOS - 关闭 View Controller 后标签栏变为透明

ios - 将 UIView 渲染为没有 subview 的图像

iphone - 如何将大 Sprite png 切成较小的 UIImages?

javascript - 在 iPad 上触摸滚动增量值

ios - ARKit 中节点函数的渲染器 didUpdate 未被执​​行

ios - 如何获取属性值符合特定条件的数组中对象的索引?

ios - 如何使用 Objective-c 为 iPhone/iPad 生成设备的唯一 ID

iphone - 如何从 NSDate 中减去小时数?

IOS:UIImage fileNamed -> 打开的文件太多