我正在开发一个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
}

最佳答案

这里有同样的问题。我可以确定地编辑GPSDictionary,我可以编辑Exif词典,但是不能编辑IPTCDictionary。我在最终的可变字典中看到了IPTCDictionary的所有键,并且基本上以与您相同的方式重写了文件。但是IPTCDictionary的密钥似乎没有写好。

也许是时候打雷达了?我将做一些进一步的测试并归档我的文件。

07-24 18:59