Paint java GUI component to image file
- by Simon
Let's say I have
JButton test = new JButton("Test Button");
and I want to draw the button into an image object and save it to a file.
I tried this:
BufferedImage b = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB);
test.paint(b.createGraphics());
File output = new File("C:\\screenie.png");
try
{
ImageIO.write(b, "png", output);…