gpt4 book ai didi

ios - 从 ALAssetRepresentation 获取 "retouched"图像

转载 作者:可可西里 更新时间:2023-11-01 05:30:10 24 4
gpt4 key购买 nike

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

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

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

最佳答案

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

关于ios - 从 ALAssetRepresentation 获取 "retouched"图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18086093/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com