ios - ALAsset defaultRepresentation fullResolutionImage

标签 ios objective-c uiimage ios7 alassetslibrary

我对新的 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/

相关文章:

iphone - 删除行时崩溃

ios - 从 UIImagepickercontroller 选择后如何保存图像

iphone - 如何拉伸(stretch) UIImage 以适合文本?

ios - EXC_BAD_ACCESS 代码=2 地址=0x0

ios - 在 Collection View Swift 中处理 n 个 gif

ios - 定义包含行、类和一般格式的自定义 NSAssert

ios - UIImage/CGImage 改变我的像素颜色

ios - 通过覆盖视频来保护 iOS 应用程序的内容

iphone - GCD : How to change timer fire interval

c++ - (iOS) 如何从 C++ 应用程序获取 UIViewController?