我对新的iOS 7照片滤镜功能有一个问题。
我的应用程序中有一个图片库。当我在UICollectionView中显示照片的缩略图时,我收到的图像已经应用了滤镜和裁剪。有两个方法可以返回"ready for use“图像:
[asset thumbnail]
[[asset defaultRepresentation] fullScreenImage]
相反,当我想分享全尺寸图片时,我收到的照片没有任何滤镜:
通过getBytes:fromOffset:length:error:实现
[[asset defaultRepresentation] fullResolutionImage]
是否可以使用适当的滤镜获得完整大小的图像?
发布于 2013-10-22 14:32:58
到目前为止,我发现只有一种方法可以得到我想要的东西。所有资源通过键@"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]];
https://stackoverflow.com/questions/18981809
复制相似问题