How to write custom metadata to PNG images in iOS

前端 未结 1 1530
难免孤独
难免孤独 2021-02-07 21:57

My application should be able to write custom metadata entries to PNG images for export to the UIPasteboard.

By piecing together various posts on the subject, I\'ve been

相关标签:
1条回答
  • 2021-02-07 22:17

    If you will try to save your image with modified metadata

    [data writeToFile:[NSTemporaryDirectory() stringByAppendingPathComponent:@"test.png"]   
           atomically:YES];
    

    And than view it properties in Finder. You will see that kCGImagePropertyPNGDescription field was setted up successfully.

    enter image description here

    But if you will try read metadata of this new file, kCGImagePropertyPNGDescription will be lost.

    ColorModel = RGB;
    Depth = 8;
    PixelHeight = 1136;
    PixelWidth = 640;
    "{PNG}" =     {
        InterlaceType = 0;
    };
    

    After some research I found that PNG doesn't contain metadata. But it may contain XMP metadata. However seems like ImageIO didn't work with XMP.
    Maybe you can try to use ImageMagic or libexif.

    Useful links:
    PNG Specification
    Reading/Writing image XMP on iPhone / Objective-c
    Does PNG support metadata fields like Author, Camera Model, etc?
    Does PNG contain EXIF data like JPG?
    libexif.sourceforge.net

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