標籤:
當使用者進行某些更改(裁剪,消除紅眼,...),在內建 Photos.app iOS上,這些更改將不會應用到由相應
fullResolutionImage
返回的
ALAssetRepresentation
照片.
但是,這些更改應用到
thumbnail
並由
fullScreenImage
返回的
ALAssetRepresentation
.
此外,有關應用的更改資訊可以在
ALAssetRepresentation
的中繼資料字典通過key
@"AdjustmentXMP"
發現.
我想這些更改應用到
fullResolutionImage
自己保持一致性.我發現在 iOS6的+
CIFilter
的
filterArrayFromSerializedXMP: 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
s有沒有可見的效果.因此,我的問題:
解答 Rank -- 0
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, free the buffer after
NSData *adata = [[NSData alloc] initWithBytesNoCopy:buffer length:representation.size freeWhenDone:YES];
// setup a dictionary with a UTI hint. The UTI hint identifies the type of image we are dealing with (ie. 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);
// cleanup memory
CFRelease(imagePropertiesDictionary);
解讀XMP中繼資料中ALAssetRepresentation