ios html语言知识 - 解释ALAssetRepresentation中的XMP元数据




html开发 html结构 (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);

我遇到了同样的问题,并找到了适合我的解决方案。 为了使它工作,在UINavigationController中实现- (NSUInteger)supportedInterfaceOrientations是不够的。 你还需要在你的控制器#3中实现这个方法,这是第一个在弹出控制器#4之后才是肖像的方法。 所以,我在我的UINavigationController中有以下代码:

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    if (self.isLandscapeOK) {
        // for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown
        return UIInterfaceOrientationMaskAll;
    }
    return UIInterfaceOrientationMaskPortrait;
}

在视图控制器#3中添加以下内容:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

你不需要添加任何东西到你的视图控制器#1,#2和#4。 这对我有用,我希望它能帮助你。





ios ios6 alassetslibrary cifilter ciimage