Get the “retouched” image from ALAssetRepresentation

会有一股神秘感。 提交于 2019-12-01 05:32:24

问题


Given an ALAssetRepresentation, is it possible to get its full resolution retouched image?

If I use the method fullResolutionImage I get the full resolution image, but unadjusted in any way.

If I use the method fullScreenImageI get the retouched image, but reduced to an appropriate for displaying full screen.


回答1:


It’s not that easy, but you can. Notice that this will also apply any cropping done by the user in the 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.


来源:https://stackoverflow.com/questions/18086093/get-the-retouched-image-from-alassetrepresentation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!