鉴于ALAssetRepresentation
,是否可以将其全分辨率修饰图像?
如果我使用方法fullResolutionImage
,我会获得完整分辨率图片,但无法以任何方式调整。
如果我使用方法fullScreenImage
,我会获得润饰后的图像,但缩小为适合显示全屏。
答案 0 :(得分: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.