首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ALAsset defaultRepresentation fullResolutionImage

ALAsset defaultRepresentation fullResolutionImage
EN

Stack Overflow用户
提问于 2013-09-24 20:36:25
回答 1查看 6.7K关注 0票数 18

我对新的iOS 7照片滤镜功能有一个问题。

我的应用程序中有一个图片库。当我在UICollectionView中显示照片的缩略图时,我收到的图像已经应用了滤镜和裁剪。有两个方法可以返回"ready for use“图像:

  • [asset thumbnail]
  • [[asset defaultRepresentation] fullScreenImage]

相反,当我想分享全尺寸图片时,我收到的照片没有任何滤镜:

通过getBytes:fromOffset:length:error:实现

  • [[asset defaultRepresentation] fullResolutionImage]
  • Read图像数据

是否可以使用适当的滤镜获得完整大小的图像?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-22 14:32:58

到目前为止,我发现只有一种方法可以得到我想要的东西。所有资源通过键@"AdjustmentXMP"将它们的修改(如过滤器、裁剪等)信息存储在元数据字典中。我们能够解释这些数据并将所有过滤器应用于fullResolutionImage,就像在这个SO answer.中一样,这是我的完整解决方案:

代码语言:javascript
复制
...
ALAssetRepresentation *assetRepresentation = [asset defaultRepresentation];
CGImageRef fullResImage = [assetRepresentation fullResolutionImage];
NSString *adjustment = [[assetRepresentation metadata] objectForKey:@"AdjustmentXMP"];
if (adjustment) {
    NSData *xmpData = [adjustment dataUsingEncoding:NSUTF8StringEncoding];
    CIImage *image = [CIImage imageWithCGImage:fullResImage];

    NSError *error = nil;
    NSArray *filterArray = [CIFilter filterArrayFromSerializedXMP:xmpData
                                                 inputImageExtent:image.extent
                                                            error:&error];
    CIContext *context = [CIContext contextWithOptions:nil];
    if (filterArray && !error) {
        for (CIFilter *filter in filterArray) {
            [filter setValue:image forKey:kCIInputImageKey];
            image = [filter outputImage];
        }
        fullResImage = [context createCGImage:image fromRect:[image extent]];
    }   
}
UIImage *result = [UIImage imageWithCGImage:fullResImage
                                      scale:[assetRepresentation scale]
                                orientation:(UIImageOrientation)[assetRepresentation orientation]];
票数 27
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18981809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档