从ALAssetRepresentation获取“修饰”图像

鉴于ALAssetRepresentation ,是否有可能获得其全分辨率修饰的图像?

如果我使用fullResolutionImage方法,我会得到完整分辨率的图像,但是没有任何调整。

如果我使用的方法fullScreenImage我得到了修饰的图像,但减less到适当的全屏显示

这并不容易,但你可以。 注意,这也将应用用户在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.