【问题标题】:ALAsset defaultRepresentation fullResolutionImageALAsset defaultRepresentation fullResolutionImage
【发布时间】:2013-09-24 12:36:24
【问题描述】:

我对新的 iOS 7 照片滤镜功能有疑问。

我的应用程序中有一个照片库。当我在 UICollectionView 中显示照片的缩略图时,我收到了已应用过滤器和裁剪的图像。有两种方法可以返回“可供使用”的图像:

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

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

是否有可能获得应用适当过滤器的全尺寸图像?

【问题讨论】:

  • 不清楚您要做什么。请重述问题,以便我们准确了解您期望达到的目标。
  • 您的代码第 5 行有拼写错误:“if (adjusment)”。您是否考虑过发布您可能的解决方案作为答案?所以我们可以投票。

标签: ios objective-c uiimage ios7 alassetslibrary


【解决方案1】:

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

...
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]];

【讨论】:

  • 谢谢它也帮助了我:)
  • 使用 iOS 8,我在元数据字典中找不到 @"AdjustmentXMP"。
  • iOS 8 中的@Andree getBytes:fromOffset:length:error: 已经为您提供了调整后的照片。无需做任何事情。
  • @Wisors kindof 是真的。但是有一个 Apple 错误,如果您在编辑后足够快地抓取它,则会返回未调整的照片。 openradar.appspot.com/radar?id=6416588328665088
猜你喜欢
  • 2015-03-06
  • 2012-07-08
  • 2011-04-08
  • 1970-01-01
  • 1970-01-01
  • 2012-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多