/** * Paints this panel to fit a new image with specified width in pixels. * The image height is computed so that the image has the same aspect * ratio as this panel. * @param width the image width, in pixels. * @return the image. */ public BufferedImage paintToImage(int width) { int wpanel = getWidth(); int hpanel = getHeight(); double scale = (double)width/(double)wpanel; int wimage = (int)(scale*wpanel+0.5); int himage = (int)(scale*hpanel+0.5); int type = BufferedImage.TYPE_INT_RGB; BufferedImage image = new BufferedImage(wimage,himage,type); paintToImage(image); return image; }
throws IOException BufferedImage image = paintToImage((int)ceil(dpi*win));