小编Sco*_*len的帖子

你如何覆盖图像元数据?

如果使用CGImageDestination在原始图像元数据中已经存在key/val,我似乎无法正确地将图像元数据写入图像.如果它们的key/val不存在于原始元数据中,它就可以正常工作.

几乎就像原始图像中的图像元数据属性优先于修改一样.这是我不知道的某种拜占庭格式问题,我需要以某种不寻常的方式填充键/ val,一个bug,还是?有人见过这个吗?

下面的代码和输出,适用于它正常工作的两种情况(如果值尚未设置)并且无法写入(如果该值已设置为其他值).

任何帮助表示非常感谢.

这是我在哪里/如何创建图像NSData:

// convert the existing asset to nsdata to overwrite itself
ALAssetRepresentation* rep = [asset defaultRepresentation];
Byte* buffer               = (Byte*)malloc(rep.size);
NSUInteger buffered        = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData* imageData          = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];

// write the metadata directly into the nsdata of the image itself
NSData* newImage = [self writeMetadataIntoImageData:imageData metadata:newMetadata];
Run Code Online (Sandbox Code Playgroud)

以下是元数据的实际修改:

- (NSData*)writeMetadataIntoImageData:(NSData*)imageData metadata:(NSMutableDictionary*)metadataAsMutable
{
    // create an imagesourceref
    CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef) imageData, NULL);

    // read and log pre write …
Run Code Online (Sandbox Code Playgroud)

cocoa metadata objective-c ios

9
推荐指数
1
解决办法
2365
查看次数

标签 统计

cocoa ×1

ios ×1

metadata ×1

objective-c ×1