得到“修饰过的”来自ALAssetRepresentation的图像 [英] Get the "retouched" image from ALAssetRepresentation

查看:86
本文介绍了得到“修饰过的”来自ALAssetRepresentation的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于 ALAssetRepresentation ,是否可以获得全分辨率修饰图像?

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

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

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

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

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

推荐答案

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

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.

这篇关于得到“修饰过的”来自ALAssetRepresentation的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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