4

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

如果我使用该方法fullResolutionImage,我将获得全分辨率图像,但未以任何方式进行调整。

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

4

1 回答 1

6

这并不容易,但你可以。请注意,这也将应用用户在 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.
于 2013-08-06T21:32:17.550 回答