- Aug 3, 2001
- 1,921
- 0
- 76
I have a JPanel that I am writing to a file by just directly calling the JPanel.paint() on the Graphics2D object of a bufferedimage (see below).
I would like to save the image at a higher resolution than the JPanel size. Is it possible to fool the Graphics2D object into scaling every draw action up? For example, the size of the JPanel is 800x600, I would like to have it write as a 3200x2400 pixel image. The paintComponent() that I am using is actually pretty complicated, so writing a special method to draw all my lines and text thicker and bigger would be annoying, and it would make modifying any code in the future a hassle.
The reason I want to do this, is that on screen the JPanel looks fine, however for print purposes the resolution needs to be much higher.
Any helpful suggestions?
Thanks.
writing JPanel graphics to file:
BufferedImage image = new BufferedImage(d.width,d.height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = image.createGraphics();
graph.paint(g2d);
ImageIO.write(image, "png", file);
I would like to save the image at a higher resolution than the JPanel size. Is it possible to fool the Graphics2D object into scaling every draw action up? For example, the size of the JPanel is 800x600, I would like to have it write as a 3200x2400 pixel image. The paintComponent() that I am using is actually pretty complicated, so writing a special method to draw all my lines and text thicker and bigger would be annoying, and it would make modifying any code in the future a hassle.
The reason I want to do this, is that on screen the JPanel looks fine, however for print purposes the resolution needs to be much higher.
Any helpful suggestions?
Thanks.
writing JPanel graphics to file:
BufferedImage image = new BufferedImage(d.width,d.height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = image.createGraphics();
graph.paint(g2d);
ImageIO.write(image, "png", file);
