ios - 解釋ALAssetRepresentation中的XMP元數據




ios6 alassetslibrary cifilter ciimage (2)

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上的內置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下生成並應用這些濾鏡?

對於第一個UITextField ,閱讀THIS教程,了解如何在鍵盤上創建按鈕。 您可以從那裡學習邏輯並使用“ Next按鈕而不是“ Done按鈕。

   //if you just want to make it appear NEXT//

    textField.returnKeyType = UIReturnKeyNext;

對於第二個UITextField ,請使用......

   // for DONE //

    textField.returnKeyType = UIReturnKeyDone;

您通常可以創建按鈕並將其重命名為任何內容,並確保在按下該按鈕的事件上給出正確的IBAction 。 如果您確實創建了自己的自定義按鈕,請查看上面的教程,了解如何將其放在正確的坐標和內容中。







ios ios6 alassetslibrary cifilter ciimage