开发者

kCGImagePropertyIPTCKeywords problem

开发者 https://www.devze.com 2023-01-02 15:08 出处:网络
I am developing an iPhone app in which I want to开发者_如何学运维 set the keywords for an image using the ImageIO framework.

I am developing an iPhone app in which I want to开发者_如何学运维 set the keywords for an image using the ImageIO framework.

Following is the code snippet that I use for setting the keywords. The problem is it does not apply the keywords to image metadata. Could someone help me out in finding the problem here?

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
}


Having the same issue here. I can edit GPSDictionary for sure, I think I can edit the Exif dictionary, but I cannot edit the IPTCDictionary. I see all the keys of the IPTCDictionary in my final Mutable Dictionary, and I basically rewrite the file the same way as you. But the key for IPTCDictionary doesn't seem to be written.

Maybe it is time for a rdar? I'll make some further tests and file mine.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号