/** * Create the tiled image and the associated graphics object that we will be used to draw the * vector features into a raster. * * <p>Note, the graphics objects will be an instance of TiledImageGraphics which is a sub-class * of Graphics2D. */ private void createImage(Dimension gridDim) { ColorModel cm = ColorModel.getRGBdefault(); SampleModel sm = cm.createCompatibleSampleModel(gridDim.width, gridDim.height); image = new TiledImage(0, 0, gridDim.width, gridDim.height, 0, 0, sm, cm); graphics = image.createGraphics(); graphics.setPaintMode(); graphics.setComposite(AlphaComposite.Src); }
graphic = ((BufferedImage) preparedImage).createGraphics(); } else if (preparedImage instanceof TiledImage) { graphic = ((TiledImage) preparedImage).createGraphics(); } else if (preparedImage instanceof VolatileImage) { graphic = ((VolatileImage) preparedImage).createGraphics();
graphic = ((BufferedImage) preparedImage).createGraphics(); } else if (preparedImage instanceof TiledImage) { graphic = ((TiledImage) preparedImage).createGraphics(); } else if (preparedImage instanceof VolatileImage) { graphic = ((VolatileImage) preparedImage).createGraphics();
/** * Create the tiled image and the associated graphics object that we will be used to * draw the vector features into a raster. * <p> * Note, the graphics objects will be an * instance of TiledImageGraphics which is a sub-class of Graphics2D. */ private void createImage( Dimension gridDim ) { ColorModel cm = ColorModel.getRGBdefault(); SampleModel sm = cm.createCompatibleSampleModel(gridDim.width, gridDim.height); image = new TiledImage(0, 0, gridDim.width, gridDim.height, 0, 0, sm, cm); graphics = image.createGraphics(); graphics.setPaintMode(); graphics.setComposite(AlphaComposite.Src); }
@Test public void testTranslatedImage() throws Exception { BufferedImage bi = new BufferedImage(256, 256, BufferedImage.TYPE_BYTE_GRAY); TiledImage image = new TiledImage(0, 0, 256, 256, 1, 1, bi.getSampleModel() .createCompatibleSampleModel(256, 256), bi.getColorModel()); Graphics g = image.createGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, 20, 20); g.setColor(new Color(20, 20, 20)); // A dark gray g.fillRect(20, 20, 20, 20); g.setColor(new Color(200, 200, 200)); // A light gray g.fillRect(0, 20, 20, 20); g.dispose(); RenderedImage indexed = quantize(image); assertTrue(indexed.getColorModel() instanceof IndexColorModel); IndexColorModel icm = (IndexColorModel) indexed.getColorModel(); assertEquals(4, icm.getMapSize()); // Black background, white fill, // light gray fill, dark gray fill = // 4 colors }