gpt4 book ai didi

ios - 解释 ALAssetRepresentation 中的 XMP 元数据

转载 作者:IT王子 更新时间:2023-10-29 07:29:27 24 4
gpt4 key购买 nike

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

但是,更改会应用于ALAssetRepresentation 返回的thumbnailfullScreenImage。此外,有关应用更改的信息可以通过键 @"AdjustmentXMP"ALAssetRepresentation 的元数据字典中找到。

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

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 没有明显的效果。因此,我的问题:

  • 有人知道创建消除红眼 CIFilter 的方法吗? (以与 Photos.app 一致的方式。具有键 kCIImageAutoAdjustRedEye 的过滤器是不够的。例如,它不接受眼睛位置的参数。)
  • 是否有可能在 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);

关于ios - 解释 ALAssetRepresentation 中的 XMP 元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13305020/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com