ios - 解釋ALAssetRepresentation中的XMP元數據




ios6 alassetslibrary cifilter ciimage (2)

當用戶在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下生成並應用這些濾鏡?

Answers

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);

我會列出我做的不適合我的事情 ,最後列出了什麼

首先,僅在安裝時運行腳本的接受答案不起作用。

刪除派生數據不起作用。

做了什麼工作:

  1. 我在Build Phases中添加了一個新的構建階段

  2. 新的複製文件階段

  3. 將所選框架拖放到放置目標中

  4. 將“目標”設置為“框架”

歸功於凱文勒的中等職位





ios ios6 alassetslibrary cifilter ciimage