0
我拍攝當前屏幕的屏幕截圖,然後保存圖像。我想打開該圖像,並能夠選擇一個特定的元素或任何我想要的圖片,並能夠反過來將該較小的選定圖像保存到 文件。請幫忙。如何選擇圖像的一部分並將該部分保存到文件
RemoteControlConfiguration config = new RemoteControlConfiguration(); config.setPort(4447);
SeleniumServer server = new SeleniumServer(config);
try{
// TODO Auto-generated method stub
server.start();
DefaultSelenium selenium = new DefaultSelenium("localhost", 4447, "*firefox", "http://www.google.com/");
selenium.start();
selenium.open("http://www.google.com/");
selenium.waitForPageToLoad("10000");
selenium.windowMaximize();
BufferedImage image1 = Screenshot("screen1.jpg");
//selenium.type("q", "Hello world");
Thread.sleep(2000);
BufferedImage image2 = Screenshot("screen2.jpg");
public static BufferedImage Screenshot(String fileName) throws Exception
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenRectangle = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRectangle);
File file = new File(fileName);
ImageIO.write(image, "jpg", file);
return image;
}
[BufferedImage.getSubimage(X,Y,W,H) ](http://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html#getSubimage%28int,%20int,%20int,%20int%29)更快(' 1行')的方式來獲得一幅圖像。 – 2011-12-17 02:22:20