javax.imageio.metadata.IIOMetadata Java Examples
The following examples show how to use
javax.imageio.metadata.IIOMetadata.
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: ShortHistogramTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private IIOMetadata upgradeMetadata(IIOMetadata src, BufferedImage bi) { String format = src.getNativeMetadataFormatName(); System.out.println("Native format: " + format); Node root = src.getAsTree(format); // add hIST node Node n = lookupChildNode(root, "hIST"); if (n == null) { System.out.println("Appending new hIST node..."); Node hIST = gethISTNode(bi); root.appendChild(hIST); } System.out.println("Upgraded metadata tree:"); dump(root, ""); System.out.println("Merging metadata..."); try { src.mergeTree(format, root); } catch (IIOInvalidTreeException e) { throw new RuntimeException("Test FAILED!", e); } return src; }
Example #2
Source File: MergeStdCommentTest.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String format = "javax_imageio_1.0"; BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next(); IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null); DOMImplementationRegistry registry; registry = DOMImplementationRegistry.newInstance(); DOMImplementation impl = registry.getDOMImplementation("XML 3.0"); Document doc = impl.createDocument(null, format, null); Element root, text, entry; root = doc.getDocumentElement(); root.appendChild(text = doc.createElement("Text")); text.appendChild(entry = doc.createElement("TextEntry")); // keyword isn't #REQUIRED by the standard metadata format. // However, it is required by the PNG format, so we include it here. entry.setAttribute("keyword", "Comment"); entry.setAttribute("value", "Some demo comment"); meta.mergeTree(format, root); }
Example #3
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 #4
Source File: GIFImageWriter.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void write(IIOMetadata sm, IIOImage iioimage, ImageWriteParam p) throws IOException { if (stream == null) { throw new IllegalStateException("output == null!"); } if (iioimage == null) { throw new IllegalArgumentException("iioimage == null!"); } if (iioimage.hasRaster()) { throw new UnsupportedOperationException("canWriteRasters() == false!"); } resetLocal(); GIFWritableStreamMetadata streamMetadata; if (sm == null) { streamMetadata = (GIFWritableStreamMetadata)getDefaultStreamMetadata(p); } else { streamMetadata = (GIFWritableStreamMetadata)convertStreamMetadata(sm, p); } write(true, true, streamMetadata, iioimage, p); }
Example #5
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 #6
Source File: JPEGImageReader.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public IIOMetadata getImageMetadata(int imageIndex) throws IOException { setThreadLock(); try { // imageMetadataIndex will always be either a valid index or // -1, in which case imageMetadata will not be null. // So we can leave checking imageIndex for gotoImage. if ((imageMetadataIndex == imageIndex) && (imageMetadata != null)) { return imageMetadata; } cbLock.check(); gotoImage(imageIndex); imageMetadata = new JPEGMetadata(false, false, iis, this); imageMetadataIndex = imageIndex; return imageMetadata; } finally { clearThreadLock(); } }
Example #7
Source File: GIFImageWriter.java From JDKSourceCode1.8 with MIT License | 6 votes |
public void prepareWriteSequence(IIOMetadata streamMetadata) throws IOException { if (stream == null) { throw new IllegalStateException("Output is not set."); } resetLocal(); // Save the possibly converted stream metadata as an instance variable. if (streamMetadata == null) { this.theStreamMetadata = (GIFWritableStreamMetadata)getDefaultStreamMetadata(null); } else { this.theStreamMetadata = new GIFWritableStreamMetadata(); convertMetadata(STREAM_METADATA_NAME, streamMetadata, theStreamMetadata); } this.isWritingSequence = true; }
Example #8
Source File: GIFImageWriter.java From Bytecoder with Apache License 2.0 | 6 votes |
public void write(IIOMetadata sm, IIOImage iioimage, ImageWriteParam p) throws IOException { if (stream == null) { throw new IllegalStateException("output == null!"); } if (iioimage == null) { throw new IllegalArgumentException("iioimage == null!"); } if (iioimage.hasRaster()) { throw new UnsupportedOperationException("canWriteRasters() == false!"); } resetLocal(); GIFWritableStreamMetadata streamMetadata; if (sm == null) { streamMetadata = (GIFWritableStreamMetadata)getDefaultStreamMetadata(p); } else { streamMetadata = (GIFWritableStreamMetadata)convertStreamMetadata(sm, p); } write(true, true, streamMetadata, iioimage, p); }
Example #9
Source File: TIFFImageWriter.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Converts a standard {@code javax_imageio_1.0} tree to a * {@code TIFFImageMetadata} object. * * @param inData The metadata object. * @return a {@code TIFFImageMetadata} or {@code null} if * the standard tree derived from the input object is {@code null}. * @throws IllegalArgumentException if {@code inData} is * {@code null}. * @throws IllegalArgumentException if {@code inData} does not support * the standard metadata format. * @throws IIOInvalidTreeException if {@code inData} generates an * invalid standard metadata tree. */ private TIFFImageMetadata convertStandardImageMetadata(IIOMetadata inData) throws IIOInvalidTreeException { if(inData == null) { throw new NullPointerException("inData == null!"); } else if(!inData.isStandardMetadataFormatSupported()) { throw new IllegalArgumentException ("inData does not support standard metadata format!"); } TIFFImageMetadata outData = null; String formatName = IIOMetadataFormatImpl.standardMetadataFormatName; Node tree = inData.getAsTree(formatName); if (tree != null) { List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1); tagSets.add(BaselineTIFFTagSet.getInstance()); outData = new TIFFImageMetadata(tagSets); outData.setFromTree(formatName, tree); } return outData; }
Example #10
Source File: GIFImageWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public void prepareWriteSequence(IIOMetadata streamMetadata) throws IOException { if (stream == null) { throw new IllegalStateException("Output is not set."); } resetLocal(); // Save the possibly converted stream metadata as an instance variable. if (streamMetadata == null) { this.theStreamMetadata = (GIFWritableStreamMetadata)getDefaultStreamMetadata(null); } else { this.theStreamMetadata = new GIFWritableStreamMetadata(); convertMetadata(STREAM_METADATA_NAME, streamMetadata, theStreamMetadata); } this.isWritingSequence = true; }
Example #11
Source File: UserPluginMetadataFormatTest.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public IIOMetadata getImageMetadata(int imageIndex) throws IOException { if (input == null) throw new IllegalStateException(); if (imageIndex >= 5 || imageIndex < 0) throw new IndexOutOfBoundsException(); if (seekForwardOnly) { if (imageIndex < minIndex) throw new IndexOutOfBoundsException(); minIndex = imageIndex; } System.out.println("Current format class name " + DummyIIOMetadataFormatImpl.class.getName()); return new DummyIIOMetadataImpl(true, DummyIIOMetadataFormatImpl.nativeMetadataFormatName, DummyIIOMetadataFormatImpl.class.getName(), null, null); }
Example #12
Source File: MergeStdCommentTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String format = "javax_imageio_1.0"; BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next(); IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null); DOMImplementationRegistry registry; registry = DOMImplementationRegistry.newInstance(); DOMImplementation impl = registry.getDOMImplementation("XML 3.0"); Document doc = impl.createDocument(null, format, null); Element root, text, entry; root = doc.getDocumentElement(); root.appendChild(text = doc.createElement("Text")); text.appendChild(entry = doc.createElement("TextEntry")); // keyword isn't #REQUIRED by the standard metadata format. // However, it is required by the PNG format, so we include it here. entry.setAttribute("keyword", "Comment"); entry.setAttribute("value", "Some demo comment"); meta.mergeTree(format, root); }
Example #13
Source File: BMPImageWriter.java From hottub with GNU General Public License v2.0 | 5 votes |
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType, ImageWriteParam param) { BMPMetadata meta = new BMPMetadata(); meta.bmpVersion = VERSION_3; meta.compression = getPreferredCompressionType(imageType); if (param != null && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) { meta.compression = BMPCompressionTypes.getType(param.getCompressionType()); } meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize(); return meta; }
Example #14
Source File: GIFImageWriter.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example #15
Source File: PNGImageWriter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { // TODO - deal with imageType if (inData instanceof PNGMetadata) { return (PNGMetadata)((PNGMetadata)inData).clone(); } else { return new PNGMetadata(inData); } }
Example #16
Source File: GIFImageWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example #17
Source File: GIFImageWriter.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Creates a default stream metadata object and merges in the * supplied metadata. */ public IIOMetadata convertStreamMetadata(IIOMetadata inData, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } IIOMetadata sm = getDefaultStreamMetadata(param); convertMetadata(STREAM_METADATA_NAME, inData, sm); return sm; }
Example #18
Source File: GIFImageWriter.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Creates a default stream metadata object and merges in the * supplied metadata. */ public IIOMetadata convertStreamMetadata(IIOMetadata inData, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } IIOMetadata sm = getDefaultStreamMetadata(param); convertMetadata(STREAM_METADATA_NAME, inData, sm); return sm; }
Example #19
Source File: ImageIOHelper.java From JewelCrawler with GNU General Public License v3.0 | 5 votes |
public static File createImage(File imageFile, String imageFormat) { File tempFile = null; try { Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(imageFormat); ImageReader reader = readers.next(); ImageInputStream iis = ImageIO.createImageInputStream(imageFile); reader.setInput(iis); // Read the stream metadata IIOMetadata streamMetadata = reader.getStreamMetadata(); // Set up the writeParam TIFFImageWriteParam tiffWriteParam = new TIFFImageWriteParam(Locale.US); tiffWriteParam.setCompressionMode(ImageWriteParam.MODE_DISABLED); // Get tif writer and set output to file Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("tiff"); ImageWriter writer = writers.next(); BufferedImage bi = reader.read(0); IIOImage image = new IIOImage(bi, null, reader.getImageMetadata(0)); tempFile = tempImageFile(imageFile); ImageOutputStream ios = ImageIO.createImageOutputStream(tempFile); writer.setOutput(ios); writer.write(streamMetadata, image, tiffWriteParam); ios.close(); writer.dispose(); reader.dispose(); } catch (Exception exc) { exc.printStackTrace(); } return tempFile; }
Example #20
Source File: JPEGImageWriter.java From JDKSourceCode1.8 with MIT License | 5 votes |
public void prepareWriteSequence(IIOMetadata streamMetadata) throws IOException { setThreadLock(); try { cbLock.check(); prepareWriteSequenceOnThread(streamMetadata); } finally { clearThreadLock(); } }
Example #21
Source File: ImageTiffFile.java From MyBox with Apache License 2.0 | 5 votes |
public static IIOMetadata getTiffIIOMetadata(File file) { try { ImageReader reader = ImageIO.getImageReadersByFormatName("tif").next(); try (ImageInputStream iis = ImageIO.createImageInputStream(file)) { reader.setInput(iis, false); IIOMetadata metadata = reader.getImageMetadata(0); reader.dispose(); return metadata; } } catch (Exception e) { logger.error(e.toString()); return null; } }
Example #22
Source File: PngDitDepthTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws IIOInvalidTreeException { // getting the writer for the png format Iterator iter = ImageIO.getImageWritersByFormatName("png"); ImageWriter writer = (ImageWriter) iter.next(); // creating a color model ColorModel colorModel = ColorModel.getRGBdefault(); // creating a sample model SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480); // creating a default metadata object IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null); String formatName = metaData.getNativeMetadataFormatName(); // first call Node metaDataNode = metaData.getAsTree(formatName); try { metaData.setFromTree(formatName, metaDataNode); } catch (Exception ex) { ex.printStackTrace(); } // second call (bitdepht is already set to an invalid value) metaDataNode = metaData.getAsTree(formatName); metaData.setFromTree(formatName, metaDataNode); }
Example #23
Source File: JPEGImageWriter.java From hottub with GNU General Public License v2.0 | 5 votes |
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType, ImageWriteParam param) { setThreadLock(); try { return new JPEGMetadata(imageType, param, this); } finally { clearThreadLock(); } }
Example #24
Source File: PngDitDepthTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws IIOInvalidTreeException { // getting the writer for the png format Iterator iter = ImageIO.getImageWritersByFormatName("png"); ImageWriter writer = (ImageWriter) iter.next(); // creating a color model ColorModel colorModel = ColorModel.getRGBdefault(); // creating a sample model SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480); // creating a default metadata object IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null); String formatName = metaData.getNativeMetadataFormatName(); // first call Node metaDataNode = metaData.getAsTree(formatName); try { metaData.setFromTree(formatName, metaDataNode); } catch (Exception ex) { ex.printStackTrace(); } // second call (bitdepht is already set to an invalid value) metaDataNode = metaData.getAsTree(formatName); metaData.setFromTree(formatName, metaDataNode); }
Example #25
Source File: ImageUtils.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
private static ImageAndResolution readAndDisplayMetadataJPEG(DSSDocument image) throws IOException { try (InputStream is = image.openStream(); ImageInputStream iis = ImageIO.createImageInputStream(is)) { ImageReader reader = getImageReader("jpeg"); // attach source to the reader reader.setInput(iis, true); int hdpi = DEFAULT_DPI; int vdpi = DEFAULT_DPI; if (isSupportedColorSpace(reader)) { // read metadata of first image IIOMetadata metadata = reader.getImageMetadata(0); Element root = (Element) metadata.getAsTree("javax_imageio_jpeg_image_1.0"); NodeList elements = root.getElementsByTagName("app0JFIF"); Element e = (Element) elements.item(0); hdpi = Integer.parseInt(e.getAttribute("Xdensity")); vdpi = Integer.parseInt(e.getAttribute("Ydensity")); } else { LOG.warn("Cannot read metadata of the image with name [{}]. The color space is not supported. " + "Using the default dpi with value [{}]", image.getName(), DEFAULT_DPI); } return new ImageAndResolution(image, hdpi, vdpi); } }
Example #26
Source File: JPEGImageWriter.java From hottub with GNU General Public License v2.0 | 5 votes |
public Dimension[] getPreferredThumbnailSizes(ImageTypeSpecifier imageType, ImageWriteParam param, IIOMetadata streamMetadata, IIOMetadata imageMetadata) { if (jfifOK(imageType, param, streamMetadata, imageMetadata)) { return (Dimension [])preferredThumbSizes.clone(); } return null; }
Example #27
Source File: GIFImageWriter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example #28
Source File: PNGCanvas.java From SwissQRBill with MIT License | 5 votes |
private static void addTextMetadata(IIOMetadata metadata) throws IIOInvalidTreeException { IIOMetadataNode textEntry = new IIOMetadataNode("tEXtEntry"); textEntry.setAttribute(METADATA_KEY_KEYWORD, "Title"); textEntry.setAttribute(METADATA_KEY_VALUE, "Swiss QR Bill"); IIOMetadataNode text = new IIOMetadataNode("tEXt"); text.appendChild(textEntry); IIOMetadataNode commentMetadata = new IIOMetadataNode(metadata.getNativeMetadataFormatName()); commentMetadata.appendChild(text); metadata.mergeTree(metadata.getNativeMetadataFormatName(), commentMetadata); }
Example #29
Source File: GIFImageWriter.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Creates a default image metadata object and merges in the * supplied metadata. */ public IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param) { if (inData == null) { throw new IllegalArgumentException("inData == null!"); } if (imageType == null) { throw new IllegalArgumentException("imageType == null!"); } GIFWritableImageMetadata im = (GIFWritableImageMetadata)getDefaultImageMetadata(imageType, param); // Save interlace flag state. boolean isProgressive = im.interlaceFlag; convertMetadata(IMAGE_METADATA_NAME, inData, im); // Undo change to interlace flag if not MODE_COPY_FROM_METADATA. if (param != null && param.canWriteProgressive() && param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) { im.interlaceFlag = isProgressive; } return im; }
Example #30
Source File: BMPImageReader.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public IIOMetadata getImageMetadata(int imageIndex) throws IOException { checkIndex(imageIndex); if (metadata == null) { try { readHeader(); } catch (IllegalArgumentException e) { throw new IIOException(I18N.getString("BMPImageReader6"), e); } } return metadata; }