Say I have
JButton test = new JButton("Test Button");
and I want to draw a 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);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
This code created an empty PNG file of size 500x500. Does anyone know how I can draw a GUI component to an image file?
Simon source
share