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

后端 未结 2 1002
花落未央
花落未央 2021-01-01 01:37

I am creating a photo editing app, and so far I\'ve managed to read the metadata from image files successfully (after getting an answer to this question: Reading Camera data

相关标签:
2条回答
  • 2021-01-01 01:52

    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.

    0 讨论(0)
  • 2021-01-01 02:10

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

    0 讨论(0)
提交回复
热议问题