kCGImagePropertyIPTC关键字问题

发布于 2024-09-05 01:28:26 字数 1028 浏览 12 评论 0原文

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

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
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文