9

我有一个 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. 如何访问照片的编辑版本?
4

2 回答 2

4

我认识到了同样的行为,并在不久前做了一些测试。让我与您分享我的结果:

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

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

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

于 2012-01-08T02:24:29.577 回答
1
-(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];
于 2015-01-30T08:53:19.527 回答