Java Code Examples for javax.imageio.IIOImage#getMetadata()
The following examples show how to use
javax.imageio.IIOImage#getMetadata() .
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: ITXtTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static ITXtTest readFrom(File f) { try { ImageInputStream iis = ImageIO.createImageInputStream(f); ImageReader r = ImageIO.getImageReaders(iis).next(); r.setInput(iis); IIOImage dst = r.readAll(0, null); // look for iTXt node IIOMetadata m = dst.getMetadata(); Node root = m.getAsTree(m.getNativeMetadataFormatName()); Node n = root.getFirstChild(); while (n != null && !"iTXt".equals(n.getNodeName())) { n = n.getNextSibling(); } if (n == null) { throw new RuntimeException("No iTXt node!"); } ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n); return t; } catch (Throwable e) { throw new RuntimeException("Reading test failed.", e); } }
Example 2
Source File: ITXtTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static ITXtTest readFrom(File f) { try { ImageInputStream iis = ImageIO.createImageInputStream(f); ImageReader r = ImageIO.getImageReaders(iis).next(); r.setInput(iis); IIOImage dst = r.readAll(0, null); // look for iTXt node IIOMetadata m = dst.getMetadata(); Node root = m.getAsTree(m.getNativeMetadataFormatName()); Node n = root.getFirstChild(); while (n != null && !"iTXt".equals(n.getNodeName())) { n = n.getNextSibling(); } if (n == null) { throw new RuntimeException("No iTXt node!"); } ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n); return t; } catch (Throwable e) { throw new RuntimeException("Reading test failed.", e); } }
Example 3
Source File: ITXtTest.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private static ITXtTest readFrom(File f) { try { ImageInputStream iis = ImageIO.createImageInputStream(f); ImageReader r = ImageIO.getImageReaders(iis).next(); r.setInput(iis); IIOImage dst = r.readAll(0, null); // look for iTXt node IIOMetadata m = dst.getMetadata(); Node root = m.getAsTree(m.getNativeMetadataFormatName()); Node n = root.getFirstChild(); while (n != null && !"iTXt".equals(n.getNodeName())) { n = n.getNextSibling(); } if (n == null) { throw new RuntimeException("No iTXt node!"); } ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n); return t; } catch (Throwable e) { throw new RuntimeException("Reading test failed.", e); } }
Example 4
Source File: ITXtTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static ITXtTest readFrom(File f) { try { ImageInputStream iis = ImageIO.createImageInputStream(f); ImageReader r = ImageIO.getImageReaders(iis).next(); r.setInput(iis); IIOImage dst = r.readAll(0, null); // look for iTXt node IIOMetadata m = dst.getMetadata(); Node root = m.getAsTree(m.getNativeMetadataFormatName()); Node n = root.getFirstChild(); while (n != null && !"iTXt".equals(n.getNodeName())) { n = n.getNextSibling(); } if (n == null) { throw new RuntimeException("No iTXt node!"); } ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n); return t; } catch (Throwable e) { throw new RuntimeException("Reading test failed.", e); } }
Example 5
Source File: ITXtTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private static ITXtTest readFrom(File f) { try { ImageInputStream iis = ImageIO.createImageInputStream(f); ImageReader r = ImageIO.getImageReaders(iis).next(); r.setInput(iis); IIOImage dst = r.readAll(0, null); // look for iTXt node IIOMetadata m = dst.getMetadata(); Node root = m.getAsTree(m.getNativeMetadataFormatName()); Node n = root.getFirstChild(); while (n != null && !"iTXt".equals(n.getNodeName())) { n = n.getNextSibling(); } if (n == null) { throw new RuntimeException("No iTXt node!"); } ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n); return t; } catch (Throwable e) { throw new RuntimeException("Reading test failed.", e); } }
Example 6
Source File: ITXtTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static ITXtTest readFrom(File f) { try (ImageInputStream imageInputStream = ImageIO.createImageInputStream(f)) { ImageReader r = ImageIO.getImageReaders(imageInputStream).next(); r.setInput(imageInputStream); IIOImage dst = r.readAll(0, null); // look for iTXt node IIOMetadata m = dst.getMetadata(); Node root = m.getAsTree(m.getNativeMetadataFormatName()); Node n = root.getFirstChild(); while (n != null && !"iTXt".equals(n.getNodeName())) { n = n.getNextSibling(); } if (n == null) { throw new RuntimeException("No iTXt node!"); } ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n); return t; } catch (Throwable e) { throw new RuntimeException("Reading test failed.", e); } }
Example 7
Source File: ITXtTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private static ITXtTest readFrom(File f) { try { ImageInputStream iis = ImageIO.createImageInputStream(f); ImageReader r = ImageIO.getImageReaders(iis).next(); r.setInput(iis); IIOImage dst = r.readAll(0, null); // look for iTXt node IIOMetadata m = dst.getMetadata(); Node root = m.getAsTree(m.getNativeMetadataFormatName()); Node n = root.getFirstChild(); while (n != null && !"iTXt".equals(n.getNodeName())) { n = n.getNextSibling(); } if (n == null) { throw new RuntimeException("No iTXt node!"); } ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n); return t; } catch (Throwable e) { throw new RuntimeException("Reading test failed.", e); } }
Example 8
Source File: ITXtTest.java From hottub with GNU General Public License v2.0 | 6 votes |
private static ITXtTest readFrom(File f) { try { ImageInputStream iis = ImageIO.createImageInputStream(f); ImageReader r = ImageIO.getImageReaders(iis).next(); r.setInput(iis); IIOImage dst = r.readAll(0, null); // look for iTXt node IIOMetadata m = dst.getMetadata(); Node root = m.getAsTree(m.getNativeMetadataFormatName()); Node n = root.getFirstChild(); while (n != null && !"iTXt".equals(n.getNodeName())) { n = n.getNextSibling(); } if (n == null) { throw new RuntimeException("No iTXt node!"); } ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n); return t; } catch (Throwable e) { throw new RuntimeException("Reading test failed.", e); } }
Example 9
Source File: ITXtTest.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private static ITXtTest readFrom(File f) { try { ImageInputStream iis = ImageIO.createImageInputStream(f); ImageReader r = ImageIO.getImageReaders(iis).next(); r.setInput(iis); IIOImage dst = r.readAll(0, null); // look for iTXt node IIOMetadata m = dst.getMetadata(); Node root = m.getAsTree(m.getNativeMetadataFormatName()); Node n = root.getFirstChild(); while (n != null && !"iTXt".equals(n.getNodeName())) { n = n.getNextSibling(); } if (n == null) { throw new RuntimeException("No iTXt node!"); } ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n); return t; } catch (Throwable e) { throw new RuntimeException("Reading test failed.", e); } }
Example 10
Source File: ITXtTest.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private static ITXtTest readFrom(File f) { try { ImageInputStream iis = ImageIO.createImageInputStream(f); ImageReader r = ImageIO.getImageReaders(iis).next(); r.setInput(iis); IIOImage dst = r.readAll(0, null); // look for iTXt node IIOMetadata m = dst.getMetadata(); Node root = m.getAsTree(m.getNativeMetadataFormatName()); Node n = root.getFirstChild(); while (n != null && !"iTXt".equals(n.getNodeName())) { n = n.getNextSibling(); } if (n == null) { throw new RuntimeException("No iTXt node!"); } ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n); return t; } catch (Throwable e) { throw new RuntimeException("Reading test failed.", e); } }
Example 11
Source File: ITXtTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private static ITXtTest readFrom(File f) { try { ImageInputStream iis = ImageIO.createImageInputStream(f); ImageReader r = ImageIO.getImageReaders(iis).next(); r.setInput(iis); IIOImage dst = r.readAll(0, null); // look for iTXt node IIOMetadata m = dst.getMetadata(); Node root = m.getAsTree(m.getNativeMetadataFormatName()); Node n = root.getFirstChild(); while (n != null && !"iTXt".equals(n.getNodeName())) { n = n.getNextSibling(); } if (n == null) { throw new RuntimeException("No iTXt node!"); } ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n); return t; } catch (Throwable e) { throw new RuntimeException("Reading test failed.", e); } }
Example 12
Source File: ITXtTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private static ITXtTest readFrom(File f) { try { ImageInputStream iis = ImageIO.createImageInputStream(f); ImageReader r = ImageIO.getImageReaders(iis).next(); r.setInput(iis); IIOImage dst = r.readAll(0, null); // look for iTXt node IIOMetadata m = dst.getMetadata(); Node root = m.getAsTree(m.getNativeMetadataFormatName()); Node n = root.getFirstChild(); while (n != null && !"iTXt".equals(n.getNodeName())) { n = n.getNextSibling(); } if (n == null) { throw new RuntimeException("No iTXt node!"); } ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n); return t; } catch (Throwable e) { throw new RuntimeException("Reading test failed.", e); } }
Example 13
Source File: ITXtTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
private static ITXtTest readFrom(File f) { try { ImageInputStream iis = ImageIO.createImageInputStream(f); ImageReader r = ImageIO.getImageReaders(iis).next(); r.setInput(iis); IIOImage dst = r.readAll(0, null); // look for iTXt node IIOMetadata m = dst.getMetadata(); Node root = m.getAsTree(m.getNativeMetadataFormatName()); Node n = root.getFirstChild(); while (n != null && !"iTXt".equals(n.getNodeName())) { n = n.getNextSibling(); } if (n == null) { throw new RuntimeException("No iTXt node!"); } ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n); return t; } catch (Throwable e) { throw new RuntimeException("Reading test failed.", e); } }
Example 14
Source File: ImageIOHelper.java From tess4j with Apache License 2.0 | 5 votes |
/** * Reads image meta data. * * @param oimage * @return a map of meta data */ public static Map<String, String> readImageData(IIOImage oimage) { Map<String, String> dict = new HashMap<String, String>(); IIOMetadata imageMetadata = oimage.getMetadata(); if (imageMetadata != null) { IIOMetadataNode dimNode = (IIOMetadataNode) imageMetadata.getAsTree("javax_imageio_1.0"); NodeList nodes = dimNode.getElementsByTagName("HorizontalPixelSize"); int dpiX; if (nodes.getLength() > 0) { float dpcWidth = Float.parseFloat(nodes.item(0).getAttributes().item(0).getNodeValue()); dpiX = (int) Math.round(25.4f / dpcWidth); } else { dpiX = Toolkit.getDefaultToolkit().getScreenResolution(); } dict.put("dpiX", String.valueOf(dpiX)); nodes = dimNode.getElementsByTagName("VerticalPixelSize"); int dpiY; if (nodes.getLength() > 0) { float dpcHeight = Float.parseFloat(nodes.item(0).getAttributes().item(0).getNodeValue()); dpiY = (int) Math.round(25.4f / dpcHeight); } else { dpiY = Toolkit.getDefaultToolkit().getScreenResolution(); } dict.put("dpiY", String.valueOf(dpiY)); } return dict; }