jjzjj

ios - ALAsset defaultRepresentation fullResolutionImage

coder 2023-07-25 原文

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

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

  • [ Assets 缩略图]
  • [[asset defaultRepresentation] fullScreenImage]

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

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

最佳答案

到目前为止,我只找到一种方法来获得我想要的东西。所有 Assets 通过键 @"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 - ALAsset defaultRepresentation fullResolutionImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18981809/

有关ios - ALAsset defaultRepresentation fullResolutionImage的更多相关文章

随机推荐