kCGImagePropertyIPTC关键词问题

时间:2010-06-09 04:08:59

标签: image metadata keyword

我正在开发一个iPhone应用程序,我想在其中使用ImageIO框架为图像设置关键字。

以下是我用于设置关键字的代码段。问题是它不会将关键字应用于图像元数据。有人可以帮我解决这个问题吗?

NSMutableDictionary *iptcDictionary = [NSDictionary dictionaryWithObject: [NSArray arrayWithObject: @"Test"] 
    forKey:(NSString *)kCGImagePropertyIPTCKeywords];

NSDictionary *newImageProperties = [NSDictionary dictionaryWithObject:iptcDictionary 
    forKey:(NSString *)kCGImagePropertyIPTCDictionary];

CGImageSourceRef imageSource=CGImageSourceCreateWithURL((CFURLRef)imageURL, nil);  //imageURL is URL of source image

CGImageDestinationRef imageDestination = CGImageDestinationCreateWithData(    
    (CFMutableDataRef)newImageFileData, CGImageSourceGetType(imageSource), 1,NULL);

CGImageDestinationAddImageFromSource(imageDestination, imageSource, 0, 
    (CFDictionaryRef) newImageProperties);

if (CGImageDestinationFinalize(imageDestination)) {
    [newImageFileData writeToFile:imagePath atomically:YES]; //imagePath is the path of the destination image with new metadata
}

1 个答案:

答案 0 :(得分:0)

这里有同样的问题。我可以肯定编辑GPSDictionary,我想我可以编辑Exif字典,但我无法编辑IPTCDictionary。我在最后的Mutable Dictionary中看到了IPTCDictionary的所有键,我基本上以与你相同的方式重写了文件。但是IPTCDictionary的关键似乎没有写出来。

也许现在是时候了吗?我会做一些进一步的测试并提交给我。

相关问题