Writing image metadata (EXIF/TIFF/IPTC) to image file in OS X

核能气质少年 提交于 2019-11-30 09:51:45
Can Poyrazoğlu

Found an answer from another StackOverflow question: How do you overwrite image metadata?:

(code taken from that question itself and modified for my needs, which contains the answer to my question)

//assuming I've already loaded the image source and read the meta
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef) data, NULL);
CFStringRef imageType = CGImageSourceGetType(source);

//new empty data to write the final image data to
NSMutableData *resultData = [NSMutableData data];
CGImageDestinationRef imgDest = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)(resultData), imageType, 1, NULL);

//copy image data
CGImageDestinationAddImageFromSource(imgDest, source, 0, (__bridge CFDictionaryRef)(window.cachedMetadata));
BOOL success = CGImageDestinationFinalize(imgDest);

This worked perfectly for writing back all the metadata including EXIF, TIFF, and IPTC.

You could try either using, or looking at the code in, the "exiv2" tool maybe.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!