Java library for reading and writing IPTC metadata to JPEG and TIFF

前端 未结 6 572
感动是毒
感动是毒 2020-12-15 20:22


Does anyone know some opensource Java library for reading and writing IPTC metadata to JPEG and TIFF? Now I\'m using Apache Sanselan. Unfortunately, it can onl

6条回答
  •  执念已碎
    2020-12-15 21:22

    For reading metadata I think you should have a look on "metadata-extractor" - an Open Source Project (Apache 2.0 licence) that develops a Java library for reading metadata from image files.

    At the moment, this project can get access to the following metadata of images:

    • Exif
    • IPTC
    • XMP
    • JFIF / JFXX
    • ICC Profiles
    • Photoshop fields

    The "metadata-extractor" is hosted at google code.

    Here is a little straightforward code-example for the 2.4.0 version:

    public void example() throws Exception {
        File jpegFile = new File("yourJpgFile.jpg");
        Metadata metadata = ImageMetadataReader.readMetadata(jpegFile);
    
        Iterator directory = metadata.getDirectoryIterator();
        while (directory.hasNext()) {
            Object tag = directory.next();
            if (tag instanceof ExifDirectory) {
                Iterator tags = ((ExifDirectory) tag).getTagIterator();
                while (tags.hasNext()) {
                    System.out.println("EXIF: "+tags.next().toString());
                }
            } else if (tag instanceof IptcDirectory) {
                Iterator tags = ((IptcDirectory) tag).getTagIterator();
                while (tags.hasNext()) {
                    System.out.println("IPTC: "+tags.next().toString());
                }
            } else if (tag instanceof JpegDirectory) {
                Iterator tags = ((JpegDirectory) tag).getTagIterator();
                while (tags.hasNext()) {
                    System.out.println("JPEG: "+tags.next().toString());
                }
            } else {
                System.err.println(tag.getClass());
            }           
        }
    }
    

提交回复
热议问题