解释ALAssetRepresentation中的XMP元数据 [英] Interpret XMP-Metadata in ALAssetRepresentation

查看:161
本文介绍了解释ALAssetRepresentation中的XMP元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户对iOS上内置的 Photos.app 中的照片进行一些更改(裁剪,消除红眼......等)时,更改不会应用于 fullResolutionImage 由相应的 ALAssetRepresentation 返回。

When a user makes some changes (cropping, red-eye removal, ...) to photos in the built-in Photos.app on iOS, the changes are not applied to the fullResolutionImage returned by the corresponding ALAssetRepresentation.

但是,更改将应用​​于缩略图 fullScreenImage c> ALAssetRepresentation 返回$ c>。
此外,有关所应用更改的信息可以在 ALAssetRepresentation 的元数据字典中通过键 @AdjustmentXMP

However, the changes are applied to the thumbnail and the fullScreenImage returned by the ALAssetRepresentation. Furthermore, information about the applied changes can be found in the ALAssetRepresentation's metadata dictionary via the key @"AdjustmentXMP".

我想将这些更改应用于 fullResolutionImage 我自己以保持一致性。我发现在 iOS6 + CIFilter filterArrayFromSerializedXMP:inputImageExtent:error:可以将此XMP元数据转换为 CIFilter 的数组:

I would like to apply these changes to the fullResolutionImage myself to preserve consistency. I've found out that on iOS6+ CIFilter's filterArrayFromSerializedXMP: inputImageExtent:error: can convert this XMP-metadata to an array of CIFilter's:

ALAssetRepresentation *rep; 
NSString *xmpString = rep.metadata[@"AdjustmentXMP"];
NSData *xmpData = [xmpString dataUsingEncoding:NSUTF8StringEncoding];

CIImage *image = [CIImage imageWithCGImage:rep.fullResolutionImage];

NSError *error = nil;
NSArray *filterArray = [CIFilter filterArrayFromSerializedXMP:xmpData 
                                             inputImageExtent:image.extent 
                                                        error:&error];
if (error) {
     NSLog(@"Error during CIFilter creation: %@", [error localizedDescription]);
}

CIContext *context = [CIContext contextWithOptions:nil];

for (CIFilter *filter in filterArray) {
     [filter setValue:image forKey:kCIInputImageKey];
     image = [filter outputImage];
}

但是,这仅适用于某些过滤器(裁剪,自动增强)但不适合红眼消除等其他人。在这些情况下, CIFilter 没有明显的效果。因此,我的问题:

However, this works only for some filters (cropping, auto-enhance) but not for others like red-eye removal. In these cases, the CIFilters have no visible effect. Therefore, my questions:


  • 是否有人知道如何创建消除红眼 CIFilter ? (以与Photos.app一致的方式。使用键 kCIImageAutoAdjustRedEye 的过滤器是不够的。例如,它不接受眼睛位置的参数。)

  • 是否有可能在iOS 5下生成并应用这些过滤器?

  • Is anyone aware of a way to create red-eye removal CIFilter? (In a way consistent with the Photos.app. The filter with the key kCIImageAutoAdjustRedEye is not enough. E.g., it does not take parameters for the position of the eyes.)
  • Is there a possibility to generate and apply these filters under iOS 5?

推荐答案

ALAssetRepresentation* representation = [[self assetAtIndex:index] defaultRepresentation];

// Create a buffer to hold the data for the asset's image
uint8_t *buffer = (Byte*)malloc(representation.size); // Copy the data from the asset into the buffer
NSUInteger length = [representation getBytes:buffer fromOffset: 0.0  length:representation.size error:nil];

if (length==0)
    return nil;

// Convert the buffer into a NSData object, and free the buffer after.

NSData *adata = [[NSData alloc] initWithBytesNoCopy:buffer length:representation.size freeWhenDone:YES];

// Set up a dictionary with a UTI hint. The UTI hint identifies the type
// of image we are dealing with (that is, a jpeg, png, or a possible
// RAW file).

// Specify the source hint.

NSDictionary* sourceOptionsDict = [NSDictionary dictionaryWithObjectsAndKeys:

(id)[representation UTI], kCGImageSourceTypeIdentifierHint, nil];

// Create a CGImageSource with the NSData. A image source can
// contain x number of thumbnails and full images.

CGImageSourceRef sourceRef = CGImageSourceCreateWithData((CFDataRef) adata,  (CFDictionaryRef) sourceOptionsDict);

[adata release];

CFDictionaryRef imagePropertiesDictionary;

// Get a copy of the image properties from the CGImageSourceRef.

imagePropertiesDictionary = CGImageSourceCopyPropertiesAtIndex(sourceRef,0, NULL);

CFNumberRef imageWidth = (CFNumberRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyPixelWidth);

CFNumberRef imageHeight = (CFNumberRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyPixelHeight);

int w = 0;

int h = 0;

CFNumberGetValue(imageWidth, kCFNumberIntType, &w);

CFNumberGetValue(imageHeight, kCFNumberIntType, &h);

// Clean up memory

CFRelease(imagePropertiesDictionary);

这篇关于解释ALAssetRepresentation中的XMP元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆