Java Code Examples for java.awt.image.RenderedImage#getPropertyNames()
The following examples show how to use
java.awt.image.RenderedImage#getPropertyNames() .
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: FXGraphics2D.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * Converts a rendered image to a {@code BufferedImage}. This utility * method has come from a forum post by Jim Moore at: * <p> * <a href="http://www.jguru.com/faq/view.jsp?EID=114602"> * http://www.jguru.com/faq/view.jsp?EID=114602</a> * * @param img the rendered image. * * @return A buffered image. */ private static BufferedImage convertRenderedImage(RenderedImage img) { if (img instanceof BufferedImage) { return (BufferedImage) img; } ColorModel cm = img.getColorModel(); int width = img.getWidth(); int height = img.getHeight(); WritableRaster raster = cm.createCompatibleWritableRaster(width, height); boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); Hashtable properties = new Hashtable(); String[] keys = img.getPropertyNames(); if (keys != null) { for (int i = 0; i < keys.length; i++) { properties.put(keys[i], img.getProperty(keys[i])); } } BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties); img.copyData(raster); return result; }
Example 2
Source File: FXGraphics2D.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * Converts a rendered image to a {@code BufferedImage}. This utility * method has come from a forum post by Jim Moore at: * <p> * <a href="http://www.jguru.com/faq/view.jsp?EID=114602"> * http://www.jguru.com/faq/view.jsp?EID=114602</a> * * @param img the rendered image. * * @return A buffered image. */ private static BufferedImage convertRenderedImage(RenderedImage img) { if (img instanceof BufferedImage) { return (BufferedImage) img; } ColorModel cm = img.getColorModel(); int width = img.getWidth(); int height = img.getHeight(); WritableRaster raster = cm.createCompatibleWritableRaster(width, height); boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); Hashtable properties = new Hashtable(); String[] keys = img.getPropertyNames(); if (keys != null) { for (int i = 0; i < keys.length; i++) { properties.put(keys[i], img.getProperty(keys[i])); } } BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties); img.copyData(raster); return result; }
Example 3
Source File: FXGraphics2D.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * Converts a rendered image to a {@code BufferedImage}. This utility * method has come from a forum post by Jim Moore at: * <p> * <a href="http://www.jguru.com/faq/view.jsp?EID=114602"> * http://www.jguru.com/faq/view.jsp?EID=114602</a> * * @param img the rendered image. * * @return A buffered image. */ private static BufferedImage convertRenderedImage(RenderedImage img) { if (img instanceof BufferedImage) { return (BufferedImage) img; } ColorModel cm = img.getColorModel(); int width = img.getWidth(); int height = img.getHeight(); WritableRaster raster = cm.createCompatibleWritableRaster(width, height); boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); Hashtable properties = new Hashtable(); String[] keys = img.getPropertyNames(); if (keys != null) { for (int i = 0; i < keys.length; i++) { properties.put(keys[i], img.getProperty(keys[i])); } } BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties); img.copyData(raster); return result; }
Example 4
Source File: FXGraphics2D.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * Converts a rendered image to a {@code BufferedImage}. This utility * method has come from a forum post by Jim Moore at: * <p> * <a href="http://www.jguru.com/faq/view.jsp?EID=114602"> * http://www.jguru.com/faq/view.jsp?EID=114602</a> * * @param img the rendered image. * * @return A buffered image. */ private static BufferedImage convertRenderedImage(RenderedImage img) { if (img instanceof BufferedImage) { return (BufferedImage) img; } ColorModel cm = img.getColorModel(); int width = img.getWidth(); int height = img.getHeight(); WritableRaster raster = cm.createCompatibleWritableRaster(width, height); boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); Hashtable properties = new Hashtable(); String[] keys = img.getPropertyNames(); if (keys != null) { for (int i = 0; i < keys.length; i++) { properties.put(keys[i], img.getProperty(keys[i])); } } BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties); img.copyData(raster); return result; }
Example 5
Source File: ImageUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public static BufferedImage rendereImage2BufferedImage( RenderedImage renderedImage ) { if (renderedImage instanceof BufferedImage) { return (BufferedImage) renderedImage; } ColorModel cm = renderedImage.getColorModel(); int width = renderedImage.getWidth(); int height = renderedImage.getHeight(); WritableRaster raster = cm.createCompatibleWritableRaster(width, height); boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); Hashtable<String, Object> properties = new Hashtable<>(); String[] keys = renderedImage.getPropertyNames(); if (keys != null) { for( int i = 0; i < keys.length; i++ ) { properties.put(keys[i], renderedImage.getProperty(keys[i])); } } BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties); renderedImage.copyData(raster); return result; }
Example 6
Source File: AWTImageTools.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Converts a java.awt.image.RenderedImage into a * java.awt.image.BufferedImage. This code was adapted from * <a href="http://www.jguru.com/faq/view.jsp?EID=114602">a jGuru post</a>. */ public static BufferedImage convertRenderedImage(final RenderedImage img) { if (img instanceof BufferedImage) return (BufferedImage) img; final ColorModel cm = img.getColorModel(); final int width = img.getWidth(); final int height = img.getHeight(); final WritableRaster raster = cm.createCompatibleWritableRaster(width, height); final boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); final Hashtable<String, Object> properties = new Hashtable<>(); final String[] keys = img.getPropertyNames(); if (keys != null) { for (int i = 0; i < keys.length; i++) { properties.put(keys[i], img.getProperty(keys[i])); } } final BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties); img.copyData(raster); return result; }
Example 7
Source File: GraphicsUtils.java From jfreesvg with GNU General Public License v3.0 | 6 votes |
/** * Converts a rendered image to a {@code BufferedImage}. This utility * method has come from a forum post by Jim Moore at: * <p> * <a href="http://www.jguru.com/faq/view.jsp?EID=114602"> * http://www.jguru.com/faq/view.jsp?EID=114602</a> * * @param img the rendered image ({@code null} not permitted). * * @return A buffered image. */ public static BufferedImage convertRenderedImage(RenderedImage img) { Args.nullNotPermitted(img, "img"); if (img instanceof BufferedImage) { return (BufferedImage) img; } ColorModel cm = img.getColorModel(); int width = img.getWidth(); int height = img.getHeight(); WritableRaster raster = cm.createCompatibleWritableRaster(width, height); boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); Hashtable properties = new Hashtable(); String[] keys = img.getPropertyNames(); if (keys != null) { for (int i = 0; i < keys.length; i++) { properties.put(keys[i], img.getProperty(keys[i])); } } BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties); img.copyData(raster); return result; }
Example 8
Source File: FXGraphics2D.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Converts a rendered image to a {@code BufferedImage}. This utility * method has come from a forum post by Jim Moore at: * <p> * <a href="http://www.jguru.com/faq/view.jsp?EID=114602"> * http://www.jguru.com/faq/view.jsp?EID=114602</a> * * @param img the rendered image. * * @return A buffered image. */ private static BufferedImage convertRenderedImage(RenderedImage img) { if (img instanceof BufferedImage) { return (BufferedImage) img; } ColorModel cm = img.getColorModel(); int width = img.getWidth(); int height = img.getHeight(); WritableRaster raster = cm.createCompatibleWritableRaster(width, height); boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); Hashtable properties = new Hashtable(); String[] keys = img.getPropertyNames(); if (keys != null) { for (int i = 0; i < keys.length; i++) { properties.put(keys[i], img.getProperty(keys[i])); } } BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties); img.copyData(raster); return result; }
Example 9
Source File: FXGraphics2D.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Converts a rendered image to a {@code BufferedImage}. This utility * method has come from a forum post by Jim Moore at: * <p> * <a href="http://www.jguru.com/faq/view.jsp?EID=114602"> * http://www.jguru.com/faq/view.jsp?EID=114602</a> * * @param img the rendered image. * * @return A buffered image. */ private static BufferedImage convertRenderedImage(RenderedImage img) { if (img instanceof BufferedImage) { return (BufferedImage) img; } ColorModel cm = img.getColorModel(); int width = img.getWidth(); int height = img.getHeight(); WritableRaster raster = cm.createCompatibleWritableRaster(width, height); boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); Hashtable properties = new Hashtable(); String[] keys = img.getPropertyNames(); if (keys != null) { for (int i = 0; i < keys.length; i++) { properties.put(keys[i], img.getProperty(keys[i])); } } BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties); img.copyData(raster); return result; }
Example 10
Source File: RasterUtils.java From geowave with Apache License 2.0 | 5 votes |
private static BufferedImage copyImage( final int targetWidth, final int targetHeight, final Color backgroundColor, final double[][] noDataValues, final RenderedImage originalImage) { Hashtable<String, Object> properties = null; if (originalImage.getPropertyNames() != null) { properties = new Hashtable<>(); for (final String name : originalImage.getPropertyNames()) { properties.put(name, originalImage.getProperty(name)); } } final SampleModel sm = originalImage.getSampleModel().createCompatibleSampleModel(targetWidth, targetHeight); final WritableRaster raster = Raster.createWritableRaster(sm, null); final ColorModel colorModel = originalImage.getColorModel(); final boolean alphaPremultiplied = colorModel.isAlphaPremultiplied(); RasterUtils.fillWithNoDataValues(raster, noDataValues); final BufferedImage image = new BufferedImage(colorModel, raster, alphaPremultiplied, properties); if (noDataValues == null) { final Graphics2D g2D = (Graphics2D) image.getGraphics(); final Color save = g2D.getColor(); g2D.setColor(backgroundColor); g2D.fillRect(0, 0, image.getWidth(), image.getHeight()); g2D.setColor(save); } return image; }
Example 11
Source File: EpsGraphics2D.java From osp with GNU General Public License v3.0 | 5 votes |
/** * Draws a RenderedImage on the EPS document. */ public void drawRenderedImage(RenderedImage img, AffineTransform xform) { Hashtable<String, Object> properties = new Hashtable<String, Object>(); String[] names = img.getPropertyNames(); for(int i = 0; i<names.length; i++) { properties.put(names[i], img.getProperty(names[i])); } ColorModel cm = img.getColorModel(); WritableRaster wr = img.copyData(null); BufferedImage img1 = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), properties); AffineTransform at = AffineTransform.getTranslateInstance(img.getMinX(), img.getMinY()); at.preConcatenate(xform); drawImage(img1, at, null); }