Java Code Examples for java.awt.image.ColorModel#createCompatibleWritableRaster()
The following examples show how to use
java.awt.image.ColorModel#createCompatibleWritableRaster() .
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: 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 2
Source File: MultipleGradientPaintContext.java From JDKSourceCode1.8 with MIT License | 6 votes |
/** * Took this cacheRaster code from GradientPaint. It appears to recycle * rasters for use by any other instance, as long as they are sufficiently * large. */ private static synchronized Raster getCachedRaster(ColorModel cm, int w, int h) { if (cm == cachedModel) { if (cached != null) { Raster ras = (Raster) cached.get(); if (ras != null && ras.getWidth() >= w && ras.getHeight() >= h) { cached = null; return ras; } } } return cm.createCompatibleWritableRaster(w, h); }
Example 3
Source File: CGLGraphicsConfig.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override public Image createAcceleratedImage(Component target, int width, int height) { ColorModel model = getColorModel(Transparency.OPAQUE); WritableRaster wr = model.createCompatibleWritableRaster(width, height); return new OffScreenImage(target, model, wr, model.isAlphaPremultiplied()); }
Example 4
Source File: AbstractFilter.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * {@inheritDoc} */ public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM) { if (destCM == null) { destCM = src.getColorModel(); } return new BufferedImage(destCM, destCM.createCompatibleWritableRaster( src.getWidth(), src.getHeight()), destCM.isAlphaPremultiplied(), null); }
Example 5
Source File: RenderToCustomBufferTest.java From hottub with GNU General Public License v2.0 | 5 votes |
private static BufferedImage createCustomBuffer() { ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorModel cm = new ComponentColorModel(cs, false, false, Transparency.OPAQUE, DataBuffer.TYPE_FLOAT); WritableRaster wr = cm.createCompatibleWritableRaster(width, height); return new BufferedImage(cm, wr, false, null); }
Example 6
Source File: BlitBg.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Override public void BlitBg(SurfaceData srcData, SurfaceData dstData, Composite comp, Region clip, int bgArgb, int srcx, int srcy, int dstx, int dsty, int width, int height) { ColorModel dstModel = dstData.getColorModel(); boolean bgHasAlpha = (bgArgb >>> 24) != 0xff; if (!dstModel.hasAlpha() && bgHasAlpha) { dstModel = ColorModel.getRGBdefault(); } WritableRaster wr = dstModel.createCompatibleWritableRaster(width, height); boolean isPremult = dstModel.isAlphaPremultiplied(); BufferedImage bimg = new BufferedImage(dstModel, wr, isPremult, null); SurfaceData tmpData = BufImgSurfaceData.createData(bimg); Color bgColor = new Color(bgArgb, bgHasAlpha); SunGraphics2D sg2d = new SunGraphics2D(tmpData, bgColor, bgColor, defaultFont); FillRect fillop = FillRect.locate(SurfaceType.AnyColor, CompositeType.SrcNoEa, tmpData.getSurfaceType()); Blit combineop = Blit.getFromCache(srcData.getSurfaceType(), CompositeType.SrcOverNoEa, tmpData.getSurfaceType()); Blit blitop = Blit.getFromCache(tmpData.getSurfaceType(), compositeType, dstData.getSurfaceType()); fillop.FillRect(sg2d, tmpData, 0, 0, width, height); combineop.Blit(srcData, tmpData, AlphaComposite.SrcOver, null, srcx, srcy, 0, 0, width, height); blitop.Blit(tmpData, dstData, comp, clip, 0, 0, dstx, dsty, width, height); }
Example 7
Source File: GLXGraphicsConfig.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public BufferedImage createCompatibleImage(int width, int height) { ColorModel model = new DirectColorModel(24, 0xff0000, 0xff00, 0xff); WritableRaster raster = model.createCompatibleWritableRaster(width, height); return new BufferedImage(model, raster, model.isAlphaPremultiplied(), null); }
Example 8
Source File: RenderToCustomBufferTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static BufferedImage createCustomBuffer() { ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorModel cm = new ComponentColorModel(cs, false, false, Transparency.OPAQUE, DataBuffer.TYPE_FLOAT); WritableRaster wr = cm.createCompatibleWritableRaster(width, height); return new BufferedImage(cm, wr, false, null); }
Example 9
Source File: GradientPaintContext.java From jdk-1.7-annotated with Apache License 2.0 | 5 votes |
static synchronized Raster getCachedRaster(ColorModel cm, int w, int h) { if (cm == cachedModel) { if (cached != null) { Raster ras = (Raster) cached.get(); if (ras != null && ras.getWidth() >= w && ras.getHeight() >= h) { cached = null; return ras; } } } return cm.createCompatibleWritableRaster(w, h); }
Example 10
Source File: GraphicsConfiguration.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Returns a <code>BufferedImage</code> that supports the specified * transparency and has a data layout and color model * compatible with this <code>GraphicsConfiguration</code>. This * method has nothing to do with memory-mapping * a device. The returned <code>BufferedImage</code> has a layout and * color model that can be optimally blitted to a device * with this <code>GraphicsConfiguration</code>. * @param width the width of the returned <code>BufferedImage</code> * @param height the height of the returned <code>BufferedImage</code> * @param transparency the specified transparency mode * @return a <code>BufferedImage</code> whose data layout and color * model is compatible with this <code>GraphicsConfiguration</code> * and also supports the specified transparency. * @throws IllegalArgumentException if the transparency is not a valid value * @see Transparency#OPAQUE * @see Transparency#BITMASK * @see Transparency#TRANSLUCENT */ public BufferedImage createCompatibleImage(int width, int height, int transparency) { if (getColorModel().getTransparency() == transparency) { return createCompatibleImage(width, height); } ColorModel cm = getColorModel(transparency); if (cm == null) { throw new IllegalArgumentException("Unknown transparency: " + transparency); } WritableRaster wr = cm.createCompatibleWritableRaster(width, height); return new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null); }
Example 11
Source File: OpCompatibleImageTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private BufferedImage createCompatible(ColorModel cm, int w, int h) { return new BufferedImage (cm, cm.createCompatibleWritableRaster(w, h), cm.isAlphaPremultiplied(), null); }
Example 12
Source File: GraphicsConfiguration.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Returns a <code>BufferedImage</code> that supports the specified * transparency and has a data layout and color model * compatible with this <code>GraphicsConfiguration</code>. This * method has nothing to do with memory-mapping * a device. The returned <code>BufferedImage</code> has a layout and * color model that can be optimally blitted to a device * with this <code>GraphicsConfiguration</code>. * @param width the width of the returned <code>BufferedImage</code> * @param height the height of the returned <code>BufferedImage</code> * @param transparency the specified transparency mode * @return a <code>BufferedImage</code> whose data layout and color * model is compatible with this <code>GraphicsConfiguration</code> * and also supports the specified transparency. * @throws IllegalArgumentException if the transparency is not a valid value * @see Transparency#OPAQUE * @see Transparency#BITMASK * @see Transparency#TRANSLUCENT */ public BufferedImage createCompatibleImage(int width, int height, int transparency) { if (getColorModel().getTransparency() == transparency) { return createCompatibleImage(width, height); } ColorModel cm = getColorModel(transparency); if (cm == null) { throw new IllegalArgumentException("Unknown transparency: " + transparency); } WritableRaster wr = cm.createCompatibleWritableRaster(width, height); return new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null); }
Example 13
Source File: GraphicsUtilities.java From orbit-image-analysis with GNU General Public License v3.0 | 3 votes |
/** * <p> * Returns a new <code>BufferedImage</code> using the same color model as the image passed as a * parameter. The returned image is only compatible with the image passed as a parameter. This * does not mean the returned image is compatible with the hardware. * </p> * * @param image * the reference image from which the color model of the new image is obtained * @return a new <code>BufferedImage</code>, compatible with the color model of <code>image</code> */ public static BufferedImage createColorModelCompatibleImage(BufferedImage image) { ColorModel cm = image.getColorModel(); return new BufferedImage(cm, cm.createCompatibleWritableRaster(image.getWidth(), image.getHeight()), cm.isAlphaPremultiplied(), null); }
Example 14
Source File: GraphicsUtilities.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * <p>Returns a new <code>BufferedImage</code> using the same color model * as the image passed as a parameter. The returned image is only compatible * with the image passed as a parameter. This does not mean the returned * image is compatible with the hardware.</p> * * @param image the reference image from which the color model of the new * image is obtained * @return a new <code>BufferedImage</code>, compatible with the color model * of <code>image</code> */ public static BufferedImage createColorModelCompatibleImage(BufferedImage image) { ColorModel cm = image.getColorModel(); return new BufferedImage(cm, cm.createCompatibleWritableRaster(image.getWidth(), image.getHeight()), cm.isAlphaPremultiplied(), null); }
Example 15
Source File: EffectUtils.java From dragonwell8_jdk with GNU General Public License v2.0 | 3 votes |
/** * <p>Returns a new <code>BufferedImage</code> using the same color model * as the image passed as a parameter. The returned image is only compatible * with the image passed as a parameter. This does not mean the returned * image is compatible with the hardware.</p> * * @param image the reference image from which the color model of the new * image is obtained * @return a new <code>BufferedImage</code>, compatible with the color model * of <code>image</code> */ public static BufferedImage createColorModelCompatibleImage(BufferedImage image) { ColorModel cm = image.getColorModel(); return new BufferedImage(cm, cm.createCompatibleWritableRaster(image.getWidth(), image.getHeight()), cm.isAlphaPremultiplied(), null); }
Example 16
Source File: SVGGraphicsConfiguration.java From jfreesvg with GNU General Public License v3.0 | 3 votes |
/** * Creates a compatible image. This override is only here to provide * support for Java 6 because from Java 7 onwards the super class has a * non-abstract implementation for this method. * * @param width the width. * @param height the height. * * @return A compatible image. */ @Override public BufferedImage createCompatibleImage(int width, int height) { ColorModel model = getColorModel(); WritableRaster raster = model.createCompatibleWritableRaster(width, height); return new BufferedImage(model, raster, model.isAlphaPremultiplied(), null); }
Example 17
Source File: EffectUtils.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * <p>Returns a new <code>BufferedImage</code> using the same color model * as the image passed as a parameter. The returned image is only compatible * with the image passed as a parameter. This does not mean the returned * image is compatible with the hardware.</p> * * @param image the reference image from which the color model of the new * image is obtained * @return a new <code>BufferedImage</code>, compatible with the color model * of <code>image</code> */ public static BufferedImage createColorModelCompatibleImage(BufferedImage image) { ColorModel cm = image.getColorModel(); return new BufferedImage(cm, cm.createCompatibleWritableRaster(image.getWidth(), image.getHeight()), cm.isAlphaPremultiplied(), null); }
Example 18
Source File: GraphicsConfiguration.java From JDKSourceCode1.8 with MIT License | 3 votes |
/** * Returns a {@link BufferedImage} with a data layout and color model * compatible with this <code>GraphicsConfiguration</code>. This * method has nothing to do with memory-mapping * a device. The returned <code>BufferedImage</code> has * a layout and color model that is closest to this native device * configuration and can therefore be optimally blitted to this * device. * @param width the width of the returned <code>BufferedImage</code> * @param height the height of the returned <code>BufferedImage</code> * @return a <code>BufferedImage</code> whose data layout and color * model is compatible with this <code>GraphicsConfiguration</code>. */ public BufferedImage createCompatibleImage(int width, int height) { ColorModel model = getColorModel(); WritableRaster raster = model.createCompatibleWritableRaster(width, height); return new BufferedImage(model, raster, model.isAlphaPremultiplied(), null); }
Example 19
Source File: GraphicsConfiguration.java From hottub with GNU General Public License v2.0 | 3 votes |
/** * Returns a {@link BufferedImage} with a data layout and color model * compatible with this <code>GraphicsConfiguration</code>. This * method has nothing to do with memory-mapping * a device. The returned <code>BufferedImage</code> has * a layout and color model that is closest to this native device * configuration and can therefore be optimally blitted to this * device. * @param width the width of the returned <code>BufferedImage</code> * @param height the height of the returned <code>BufferedImage</code> * @return a <code>BufferedImage</code> whose data layout and color * model is compatible with this <code>GraphicsConfiguration</code>. */ public BufferedImage createCompatibleImage(int width, int height) { ColorModel model = getColorModel(); WritableRaster raster = model.createCompatibleWritableRaster(width, height); return new BufferedImage(model, raster, model.isAlphaPremultiplied(), null); }
Example 20
Source File: GraphicsUtilities.java From pgptool with GNU General Public License v3.0 | 2 votes |
/** * <p> * Returns a new <code>BufferedImage</code> using the same color model as the * image passed as a parameter. The returned image is only compatible with the * image passed as a parameter. This does not mean the returned image is * compatible with the hardware. * </p> * * @param image * the reference image from which the color model of the new image is * obtained * @return a new <code>BufferedImage</code>, compatible with the color model of * <code>image</code> */ public static BufferedImage createColorModelCompatibleImage(BufferedImage image) { ColorModel cm = image.getColorModel(); return new BufferedImage(cm, cm.createCompatibleWritableRaster(image.getWidth(), image.getHeight()), cm.isAlphaPremultiplied(), null); }