suppose I wanted to create a BufferedImage, except it i would have to capture it on a window that is minimized. How should I do this? Thanks!
Printable View
suppose I wanted to create a BufferedImage, except it i would have to capture it on a window that is minimized. How should I do this? Thanks!
If the window is not showing, then the Robot class is no use.
An idea: Create a BufferedImage, get its graphics context and call the window's paint method to have it draw itself on your image.
Sorry, I don't have any examples.
any ideas? I'm stumped.
Have you tried what I suggested earlier:
Create a BufferedImage,
get its graphics context
call the window's paint method with the graphics to have it draw itself on your image.
Searching on this forum for new BufferedImage( found code examples for the first two steps.
The third step would be:
windowRef.paint(g); // for AWT
or
windowRef.paintComponent(g); // for swing
Now your buffered image contains what the window would have painted on the screen.
I don't know about the window's contained components. Try it and see what you get
Okay, This is how i paint a component:
and here is how i call this method:Code:public static BufferedImage paintComponent(Graphics g) {
BufferedImage grid = null;
x.paintComponents(g); // paint background
Graphics2D g2 = (Graphics2D)g; // we need a Graphics2D context
int w = x.getWidth();
int h = x.getHeight();
grid = (BufferedImage)(x.createImage(w,h));
return grid;
}
When I see the saved image, I see nothing but white. "x" refers to another window that is opened. What is happening?Code:Graphics g = x.getGraphics();
BufferedImage picImageArea = paintComponent(g);
try {
ImageIO.write(picImageArea, "png", new File("test.png"));
} catch (IOException e1) {
e1.printStackTrace();
}
That is not the signature for the component's paintComponent method.Code:public static BufferedImage paintComponent(Graphics g) {
Are you intending to override the component's method?
What is x???Code:x.paintComponents(g); // paint background
I don't understand your code.Quote:
What is happening?
How does it relate to what I suggested?
The three steps:
BufferedImage bi = new BufferedImage( ....);
Graphics g = bi.getGraphics();
windowRef.paint(g); // have the window paint itself on our image