A
aidy
Hi,
I am trying to take a screenshot of an active window and save it to a
file. I've used some code from the SUN site
<code>
import java.awt.Rectangle;
import java.awt.Robot;
import javax.imageio.ImageIO;
import java.io.File;
import java.awt.image.BufferedImage;
public class Main {
try{
// Get the screen size
Rectangle rectangle = new Rectangle(this.getBounds());
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(rectangle);
File file;
// Save the screenshot as a png
file = new File("screen.png");
ImageIO.write(image, "png", file);
// Save the screenshot as a jpg
file = new File("screen.jpg");
ImageIO.write(image, "jpg", file);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
<code>
As you may guess I am new to Java.
q1. I am having problems with what to put in the above classes getbound
method.
q2. I am getting compile errors on the main braces for some reason.
Any pointers would be greatly appreciated.
Aidy
I am trying to take a screenshot of an active window and save it to a
file. I've used some code from the SUN site
<code>
import java.awt.Rectangle;
import java.awt.Robot;
import javax.imageio.ImageIO;
import java.io.File;
import java.awt.image.BufferedImage;
public class Main {
try{
// Get the screen size
Rectangle rectangle = new Rectangle(this.getBounds());
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(rectangle);
File file;
// Save the screenshot as a png
file = new File("screen.png");
ImageIO.write(image, "png", file);
// Save the screenshot as a jpg
file = new File("screen.jpg");
ImageIO.write(image, "jpg", file);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
<code>
As you may guess I am new to Java.
q1. I am having problems with what to put in the above classes getbound
method.
q2. I am getting compile errors on the main braces for some reason.
Any pointers would be greatly appreciated.
Aidy