kCGImagePropertyIPTC关键字问题
我正在开发一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论