From: Michael B. <mic...@gm...> - 2009-10-28 05:00:29
|
Hi Oliver, Thanks for the question. It's prompted me to look at the JMapPane code and see how to make it easier to save an image. In GeoTools 2.6.0 you can get the map pane's cached image with mapPane.getBaseImage() but the image is configured for saving easily to JPG. I'll make some changes to the code and put together a new example. Meanwhile, here is a method that should work... Rectangle paintArea = mapPane.getVisibleRect(); BufferedImage image = new BufferedImage( paintArea.width, paintArea.height, BufferedImage.TYPE_INT_RGB); Graphics2D gr = image.createGraphics(); gr.setComposite(AlphaComposite.Src); gr.setPaint(Color.WHITE); gr.fill(paintArea); mapPane.getRenderer().paint(gr, mapPane.getVisibleRect(), mapPane.getDisplayArea(), mapPane.getWorldToScreenTransform()); File fileToSave = ... try { ImageIO.write(image, "jpeg", fileToSave); } catch (IOException ex) { // bummer... } finally { gr.dispose(); } Hope that helps. Michael |