Java Code Examples for javax.imageio.metadata.IIOMetadata#getMetadataFormatNames()

The following examples show how to use javax.imageio.metadata.IIOMetadata#getMetadataFormatNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExifGpsWriter.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Main method to write the gps data to the exif 
 * @param gps - gps position to be added
 * @throws IOException 
 */
private void writeExif() throws IOException {

    IIOMetadata metadata = jpegReader.getImageMetadata(0);

    // names says which exif tree to get - 0 for jpeg 1 for the default
    String[] names = metadata.getMetadataFormatNames();
    IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(names[0]);

    // exif is on the app1 node called unknown
    NodeList nList = root.getElementsByTagName("unknown");
    IIOMetadataNode app1EXIFNode = (IIOMetadataNode) nList.item(0);
    ArrayList<IIOMetadata> md = readExif(app1EXIFNode);
    IIOMetadata exifMetadata = md.get(0);

    // insert the gps data into the exif
    exifMetadata = insertGPSCoords(exifMetadata);

    // create a new exif node
    IIOMetadataNode app1NodeNew = createNewExifNode(exifMetadata, null, null);

    // copy the user data accross
    app1EXIFNode.setUserObject(app1NodeNew.getUserObject());

    // write to a new image file
    FileImageOutputStream out1 = new FileImageOutputStream(new File("GPS_" + imageFile.getName()));
    jpegWriter.setOutput(out1);
    metadata.setFromTree(names[0], root);

    IIOImage image = new IIOImage(jpegReader.readAsRenderedImage(0, jpegReader.getDefaultReadParam()), null, metadata);

    // write out the new image
    jpegWriter.write(jpegReader.getStreamMetadata(), image, jpegWriter.getDefaultWriteParam());

}
 
Example 2
Source File: MergeTreeTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    ImageWriter iw =
        (ImageWriter)ImageIO.getImageWritersByFormatName("jpeg").next();

    ImageTypeSpecifier type =
        ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);

    ImageOutputStream ios =
        ImageIO.createImageOutputStream(new File("MergeTreeTest.jpeg"));
    iw.setOutput(ios);

    IIOMetadata meta = iw.getDefaultImageMetadata(type, null);

    boolean isFailed = false;

    String[] fmts = meta.getMetadataFormatNames();
    for (int i=0; i<fmts.length; i++) {
        System.out.print("Format: " + fmts[i] + " ... ");
        Node root = meta.getAsTree(fmts[i]);
        try {
            meta.mergeTree(fmts[i], root);
        } catch (NullPointerException e) {
            throw new RuntimeException("Test failed for format " + fmts[i], e);
        }
        System.out.println("PASSED");
    }
}
 
Example 3
Source File: MergeTreeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    ImageWriter iw =
        (ImageWriter)ImageIO.getImageWritersByFormatName("jpeg").next();

    ImageTypeSpecifier type =
        ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);

    ImageOutputStream ios =
        ImageIO.createImageOutputStream(new File("MergeTreeTest.jpeg"));
    iw.setOutput(ios);

    IIOMetadata meta = iw.getDefaultImageMetadata(type, null);

    boolean isFailed = false;

    String[] fmts = meta.getMetadataFormatNames();
    for (int i=0; i<fmts.length; i++) {
        System.out.print("Format: " + fmts[i] + " ... ");
        Node root = meta.getAsTree(fmts[i]);
        try {
            meta.mergeTree(fmts[i], root);
        } catch (NullPointerException e) {
            throw new RuntimeException("Test failed for format " + fmts[i], e);
        }
        System.out.println("PASSED");
    }
}
 
Example 4
Source File: UserPluginMetadataFormatTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {

        DummyImageReaderImpl reader;

        reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());

        byte[] data = new byte[1024];
        ByteArrayInputStream bais =
            new ByteArrayInputStream(data);

        reader.setInput(ImageIO.createImageInputStream(bais));
        IIOMetadata metadata = reader.getImageMetadata(1);
        if(metadata == null) {
            throw new RuntimeException("IIOMetada is NULL");
        }

        String[] formatNames = metadata.getMetadataFormatNames();

        for(int j=0; j<formatNames.length; j++) {

            String formatName = formatNames[j];
            System.out.println("\nFormat Names : " + formatName);

            try {
                IIOMetadataFormat metadataFormat =
                    metadata.getMetadataFormat(formatName);
                System.out.println("  Class Name " +
                                   metadataFormat.getClass());
            } catch(IllegalStateException ise) {
                Throwable t = ise;
                t.printStackTrace();
                while(t.getCause() != null) {
                    t = t.getCause();
                    t.printStackTrace();
                }
                // test failed!
                // stop applet!
                System.out.println("Test faied.");
                throw new RuntimeException("Test failed.", ise);
            }
        }
    }
 
Example 5
Source File: UserPluginMetadataFormatTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {

        DummyImageReaderImpl reader;

        reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());

        byte[] data = new byte[1024];
        ByteArrayInputStream bais =
            new ByteArrayInputStream(data);

        reader.setInput(ImageIO.createImageInputStream(bais));
        IIOMetadata metadata = reader.getImageMetadata(1);
        if(metadata == null) {
            throw new RuntimeException("IIOMetada is NULL");
        }

        String[] formatNames = metadata.getMetadataFormatNames();

        for(int j=0; j<formatNames.length; j++) {

            String formatName = formatNames[j];
            System.out.println("\nFormat Names : " + formatName);

            try {
                IIOMetadataFormat metadataFormat =
                    metadata.getMetadataFormat(formatName);
                System.out.println("  Class Name " +
                                   metadataFormat.getClass());
            } catch(IllegalStateException ise) {
                Throwable t = ise;
                t.printStackTrace();
                while(t.getCause() != null) {
                    t = t.getCause();
                    t.printStackTrace();
                }
                // test failed!
                // stop applet!
                System.out.println("Test faied.");
                throw new RuntimeException("Test failed.", ise);
            }
        }
    }
 
Example 6
Source File: UserPluginMetadataFormatTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {

        DummyImageReaderImpl reader;

        reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());

        byte[] data = new byte[1024];
        ByteArrayInputStream bais =
            new ByteArrayInputStream(data);

        reader.setInput(ImageIO.createImageInputStream(bais));
        IIOMetadata metadata = reader.getImageMetadata(1);
        if(metadata == null) {
            throw new RuntimeException("IIOMetada is NULL");
        }

        String[] formatNames = metadata.getMetadataFormatNames();

        for(int j=0; j<formatNames.length; j++) {

            String formatName = formatNames[j];
            System.out.println("\nFormat Names : " + formatName);

            try {
                IIOMetadataFormat metadataFormat =
                    metadata.getMetadataFormat(formatName);
                System.out.println("  Class Name " +
                                   metadataFormat.getClass());
            } catch(IllegalStateException ise) {
                Throwable t = ise;
                t.printStackTrace();
                while(t.getCause() != null) {
                    t = t.getCause();
                    t.printStackTrace();
                }
                // test failed!
                // stop applet!
                System.out.println("Test faied.");
                throw new RuntimeException("Test failed.", ise);
            }
        }
    }
 
Example 7
Source File: UserPluginMetadataFormatTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {

        DummyImageReaderImpl reader;

        reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());

        byte[] data = new byte[1024];
        ByteArrayInputStream bais =
            new ByteArrayInputStream(data);

        reader.setInput(ImageIO.createImageInputStream(bais));
        IIOMetadata metadata = reader.getImageMetadata(1);
        if(metadata == null) {
            throw new RuntimeException("IIOMetada is NULL");
        }

        String[] formatNames = metadata.getMetadataFormatNames();

        for(int j=0; j<formatNames.length; j++) {

            String formatName = formatNames[j];
            System.out.println("\nFormat Names : " + formatName);

            try {
                IIOMetadataFormat metadataFormat =
                    metadata.getMetadataFormat(formatName);
                System.out.println("  Class Name " +
                                   metadataFormat.getClass());
            } catch(IllegalStateException ise) {
                Throwable t = ise;
                t.printStackTrace();
                while(t.getCause() != null) {
                    t = t.getCause();
                    t.printStackTrace();
                }
                // test failed!
                // stop applet!
                System.out.println("Test faied.");
                throw new RuntimeException("Test failed.", ise);
            }
        }
    }
 
Example 8
Source File: UserPluginMetadataFormatTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {

        DummyImageReaderImpl reader;

        reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());

        byte[] data = new byte[1024];
        ByteArrayInputStream bais =
            new ByteArrayInputStream(data);

        reader.setInput(ImageIO.createImageInputStream(bais));
        IIOMetadata metadata = reader.getImageMetadata(1);
        if(metadata == null) {
            throw new RuntimeException("IIOMetada is NULL");
        }

        String[] formatNames = metadata.getMetadataFormatNames();

        for(int j=0; j<formatNames.length; j++) {

            String formatName = formatNames[j];
            System.out.println("\nFormat Names : " + formatName);

            try {
                IIOMetadataFormat metadataFormat =
                    metadata.getMetadataFormat(formatName);
                System.out.println("  Class Name " +
                                   metadataFormat.getClass());
            } catch(IllegalStateException ise) {
                Throwable t = ise;
                t.printStackTrace();
                while(t.getCause() != null) {
                    t = t.getCause();
                    t.printStackTrace();
                }
                // test failed!
                // stop applet!
                System.out.println("Test faied.");
                throw new RuntimeException("Test failed.", ise);
            }
        }
    }
 
Example 9
Source File: UserPluginMetadataFormatTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {

        DummyImageReaderImpl reader;

        reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());

        byte[] data = new byte[1024];
        ByteArrayInputStream bais =
            new ByteArrayInputStream(data);

        reader.setInput(ImageIO.createImageInputStream(bais));
        IIOMetadata metadata = reader.getImageMetadata(1);
        if(metadata == null) {
            throw new RuntimeException("IIOMetada is NULL");
        }

        String[] formatNames = metadata.getMetadataFormatNames();

        for(int j=0; j<formatNames.length; j++) {

            String formatName = formatNames[j];
            System.out.println("\nFormat Names : " + formatName);

            try {
                IIOMetadataFormat metadataFormat =
                    metadata.getMetadataFormat(formatName);
                System.out.println("  Class Name " +
                                   metadataFormat.getClass());
            } catch(IllegalStateException ise) {
                Throwable t = ise;
                t.printStackTrace();
                while(t.getCause() != null) {
                    t = t.getCause();
                    t.printStackTrace();
                }
                // test failed!
                // stop applet!
                System.out.println("Test faied.");
                throw new RuntimeException("Test failed.", ise);
            }
        }
    }
 
Example 10
Source File: UserPluginMetadataFormatTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {

        DummyImageReaderImpl reader;

        reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());

        byte[] data = new byte[1024];
        ByteArrayInputStream bais =
            new ByteArrayInputStream(data);

        reader.setInput(ImageIO.createImageInputStream(bais));
        IIOMetadata metadata = reader.getImageMetadata(1);
        if(metadata == null) {
            throw new RuntimeException("IIOMetada is NULL");
        }

        String[] formatNames = metadata.getMetadataFormatNames();

        for(int j=0; j<formatNames.length; j++) {

            String formatName = formatNames[j];
            System.out.println("\nFormat Names : " + formatName);

            try {
                IIOMetadataFormat metadataFormat =
                    metadata.getMetadataFormat(formatName);
                System.out.println("  Class Name " +
                                   metadataFormat.getClass());
            } catch(IllegalStateException ise) {
                Throwable t = ise;
                t.printStackTrace();
                while(t.getCause() != null) {
                    t = t.getCause();
                    t.printStackTrace();
                }
                // test failed!
                // stop applet!
                System.out.println("Test faied.");
                throw new RuntimeException("Test failed.", ise);
            }
        }
    }
 
Example 11
Source File: UserPluginMetadataFormatTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {

        DummyImageReaderImpl reader;

        reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());

        byte[] data = new byte[1024];
        ByteArrayInputStream bais =
            new ByteArrayInputStream(data);

        reader.setInput(ImageIO.createImageInputStream(bais));
        IIOMetadata metadata = reader.getImageMetadata(1);
        if(metadata == null) {
            throw new RuntimeException("IIOMetada is NULL");
        }

        String[] formatNames = metadata.getMetadataFormatNames();

        for(int j=0; j<formatNames.length; j++) {

            String formatName = formatNames[j];
            System.out.println("\nFormat Names : " + formatName);

            try {
                IIOMetadataFormat metadataFormat =
                    metadata.getMetadataFormat(formatName);
                System.out.println("  Class Name " +
                                   metadataFormat.getClass());
            } catch(IllegalStateException ise) {
                Throwable t = ise;
                t.printStackTrace();
                while(t.getCause() != null) {
                    t = t.getCause();
                    t.printStackTrace();
                }
                // test failed!
                // stop applet!
                System.out.println("Test faied.");
                throw new RuntimeException("Test failed.", ise);
            }
        }
    }
 
Example 12
Source File: UserPluginMetadataFormatTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {

        DummyImageReaderImpl reader;

        reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());

        byte[] data = new byte[1024];
        ByteArrayInputStream bais =
            new ByteArrayInputStream(data);

        reader.setInput(ImageIO.createImageInputStream(bais));
        IIOMetadata metadata = reader.getImageMetadata(1);
        if(metadata == null) {
            throw new RuntimeException("IIOMetada is NULL");
        }

        String[] formatNames = metadata.getMetadataFormatNames();

        for(int j=0; j<formatNames.length; j++) {

            String formatName = formatNames[j];
            System.out.println("\nFormat Names : " + formatName);

            try {
                IIOMetadataFormat metadataFormat =
                    metadata.getMetadataFormat(formatName);
                System.out.println("  Class Name " +
                                   metadataFormat.getClass());
            } catch(IllegalStateException ise) {
                Throwable t = ise;
                t.printStackTrace();
                while(t.getCause() != null) {
                    t = t.getCause();
                    t.printStackTrace();
                }
                // test failed!
                // stop applet!
                System.out.println("Test faied.");
                throw new RuntimeException("Test failed.", ise);
            }
        }
    }
 
Example 13
Source File: UserPluginMetadataFormatTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {

        DummyImageReaderImpl reader;

        reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());

        byte[] data = new byte[1024];
        ByteArrayInputStream bais =
            new ByteArrayInputStream(data);

        reader.setInput(ImageIO.createImageInputStream(bais));
        IIOMetadata metadata = reader.getImageMetadata(1);
        if(metadata == null) {
            throw new RuntimeException("IIOMetada is NULL");
        }

        String[] formatNames = metadata.getMetadataFormatNames();

        for(int j=0; j<formatNames.length; j++) {

            String formatName = formatNames[j];
            System.out.println("\nFormat Names : " + formatName);

            try {
                IIOMetadataFormat metadataFormat =
                    metadata.getMetadataFormat(formatName);
                System.out.println("  Class Name " +
                                   metadataFormat.getClass());
            } catch(IllegalStateException ise) {
                Throwable t = ise;
                t.printStackTrace();
                while(t.getCause() != null) {
                    t = t.getCause();
                    t.printStackTrace();
                }
                // test failed!
                // stop applet!
                System.out.println("Test faied.");
                throw new RuntimeException("Test failed.", ise);
            }
        }
    }
 
Example 14
Source File: UserPluginMetadataFormatTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {

        DummyImageReaderImpl reader;

        reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());

        byte[] data = new byte[1024];
        ByteArrayInputStream bais =
            new ByteArrayInputStream(data);

        reader.setInput(ImageIO.createImageInputStream(bais));
        IIOMetadata metadata = reader.getImageMetadata(1);
        if(metadata == null) {
            throw new RuntimeException("IIOMetada is NULL");
        }

        String[] formatNames = metadata.getMetadataFormatNames();

        for(int j=0; j<formatNames.length; j++) {

            String formatName = formatNames[j];
            System.out.println("\nFormat Names : " + formatName);

            try {
                IIOMetadataFormat metadataFormat =
                    metadata.getMetadataFormat(formatName);
                System.out.println("  Class Name " +
                                   metadataFormat.getClass());
            } catch(IllegalStateException ise) {
                Throwable t = ise;
                t.printStackTrace();
                while(t.getCause() != null) {
                    t = t.getCause();
                    t.printStackTrace();
                }
                // test failed!
                // stop applet!
                System.out.println("Test faied.");
                throw new RuntimeException("Test failed.", ise);
            }
        }
    }
 
Example 15
Source File: ImageFileReaders.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static void readImageMetaData(String format,
            ImageInformation imageInfo, IIOMetadata iioMetaData) {
        try {
            if (imageInfo == null || iioMetaData == null) {
                return;
            }
            StringBuilder metaDataXml = new StringBuilder();
            String[] formatNames = iioMetaData.getMetadataFormatNames();
            Map<String, Map<String, List<Map<String, Object>>>> metaData = new HashMap<>();
            for (String formatName : formatNames) {
                Map<String, List<Map<String, Object>>> formatMetaData = new HashMap<>();
                IIOMetadataNode tree = (IIOMetadataNode) iioMetaData.getAsTree(formatName);
                readImageMetaData(formatMetaData, metaDataXml, tree, 2);
                metaData.put(formatName, formatMetaData);
            }
            imageInfo.setMetaData(metaData);
            imageInfo.setMetaDataXml(metaDataXml.toString());

            explainCommonMetaData(metaData, imageInfo);
            switch (format.toLowerCase()) {
                case "png":
                    ImagePngFile.explainPngMetaData(metaData, imageInfo);
                    break;
                case "jpg":
                case "jpeg":
                    ImageJpgFile.explainJpegMetaData(metaData, imageInfo);
                    break;
                case "gif":
                    ImageGifFile.explainGifMetaData(metaData, imageInfo);
                    break;
                case "bmp":
                    ImageBmpFile.explainBmpMetaData(metaData, imageInfo);
                    break;
                case "tif":
                case "tiff":
                    ImageTiffFile.explainTiffMetaData(iioMetaData, imageInfo);
                    break;
                default:

            }
//            logger.debug(metaData);

        } catch (Exception e) {
            logger.error(e.toString());
        }
    }
 
Example 16
Source File: UserPluginMetadataFormatTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {

        DummyImageReaderImpl reader;

        reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());

        byte[] data = new byte[1024];
        ByteArrayInputStream bais =
            new ByteArrayInputStream(data);

        reader.setInput(ImageIO.createImageInputStream(bais));
        IIOMetadata metadata = reader.getImageMetadata(1);
        if(metadata == null) {
            throw new RuntimeException("IIOMetada is NULL");
        }

        String[] formatNames = metadata.getMetadataFormatNames();

        for(int j=0; j<formatNames.length; j++) {

            String formatName = formatNames[j];
            System.out.println("\nFormat Names : " + formatName);

            try {
                IIOMetadataFormat metadataFormat =
                    metadata.getMetadataFormat(formatName);
                System.out.println("  Class Name " +
                                   metadataFormat.getClass());
            } catch(IllegalStateException ise) {
                Throwable t = ise;
                t.printStackTrace();
                while(t.getCause() != null) {
                    t = t.getCause();
                    t.printStackTrace();
                }
                // test failed!
                // stop applet!
                System.out.println("Test faied.");
                throw new RuntimeException("Test failed.", ise);
            }
        }
    }
 
Example 17
Source File: UserPluginMetadataFormatTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {

        DummyImageReaderImpl reader;

        reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());

        byte[] data = new byte[1024];
        ByteArrayInputStream bais =
            new ByteArrayInputStream(data);

        reader.setInput(ImageIO.createImageInputStream(bais));
        IIOMetadata metadata = reader.getImageMetadata(1);
        if(metadata == null) {
            throw new RuntimeException("IIOMetada is NULL");
        }

        String[] formatNames = metadata.getMetadataFormatNames();

        for(int j=0; j<formatNames.length; j++) {

            String formatName = formatNames[j];
            System.out.println("\nFormat Names : " + formatName);

            try {
                IIOMetadataFormat metadataFormat =
                    metadata.getMetadataFormat(formatName);
                System.out.println("  Class Name " +
                                   metadataFormat.getClass());
            } catch(IllegalStateException ise) {
                Throwable t = ise;
                t.printStackTrace();
                while(t.getCause() != null) {
                    t = t.getCause();
                    t.printStackTrace();
                }
                // test failed!
                // stop applet!
                System.out.println("Test faied.");
                throw new RuntimeException("Test failed.", ise);
            }
        }
    }