【问题标题】:Access cropped or edited images using ALAssetsLibrary使用 ALAssetsLibrary 访问裁剪或编辑的图像
【发布时间】:2012-02-04 22:38:05
【问题描述】:

我有一个 ipad 应用程序,它使用 ALAssetsLibrary 从照片应用程序中获取图像,然后将它们上传到网络服务器。到目前为止,一切正常。

现在,如果我转到照片应用程序并编辑图像(例如裁剪)并上传,则原始未裁剪的图像将被上传。我正在使用资产 url 访问/保存照片。

例如:

createPhoto: 
assetUrl: assets-library://asset/asset.JPG?id=542F09CA-00E1-412E-A7E6-0C222E3F8FFB&ext=JPG, 
UTIs: (
    "public.jpeg"
), 
UTI:public.jpeg

这不是ALAssetsLibrary 缓存问题,因为我已经尝试过编辑、杀死应用程序、启动、上传仍然上传旧图像。

问题:

  1. 我如何知道照片的编辑(裁剪/红眼/增强)版本是否可用?
  2. 如何访问照片的编辑版本?

【问题讨论】:

    标签: objective-c ios ipad alassetslibrary


    【解决方案1】:

    我发现了同样的行为,并在不久前进行了一些测试。让我与您分享我的结果:

    1. 你只能通过 fullScreenImage 方法获得的编辑图像。 Apple的文档中也提到了这一点: “在 iOS 5 及更高版本中,此方法返回经过完全裁剪、旋转和调整的图像——与用户在照片或图像选择器中看到的完全一样。”

    2. fullResolutionImage 和 getBytes 方法返回未编辑的图像。但是,裁剪等编辑参数保存在图像元数据中。但是,此元数据信息仅由 Aperture 和 iPhoto 等 Apple 应用程序解释。

    3. 您可以通过检查图像元数据来确定图像是否已被编辑。比较未编辑和已编辑图像的元数据,并查找元数据字段中的差异。

    【讨论】:

    • 我打印了 CGImageRef 的宽度和高度 ` fullResolutionImage: 3968 X 2232 fullScreenImage: 841 X 1024 ` 不幸的是 fullScreenImage 比全屏图像小得多。我需要上传完整大小的编辑图像。有没有其他方法可以访问编辑后的全分辨率图像。
    • 不幸的是,没有 API 可供 3rd 方应用程序执行此操作。
    【解决方案2】:
    -(UIImage*)fullScreenImage:(ALAsset *)imageAsset{
        ALAssetRepresentation *assetRepresentation = [imageAsset 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]];
        return result;
    }
    

    在上面的函数中传递 ALAsset 值然后你编辑的图像...:)

    以上代码用于从元数据中获取编辑后的图像

    如果您使用全屏图像,那么您也将获得编辑后的图像

    ALAssetRepresentation *representation = [asset defaultRepresentation];
     CGImageRef iref = [representation fullScreenImage];
     UIImage *editedImage = [UIImage imageWithCGImage:iref];
    

    【讨论】:

      猜你喜欢
      • 2017-05-22
      • 2011-07-12
      • 1970-01-01
      • 1970-01-01
      • 2011-09-14
      • 1970-01-01
      • 2014-07-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多