如何用java读取屏幕图象
1个回答
展开全部
大概思路就是下面这样了width=|x1-x2|,high=|y1-y2|
class ScreenCapture
{
/**
* @param args
*/
private Robot robot = null;
private Rectangle scrRect = null;
int x1,y1;
int width,high;
public ScreenCapture()
{
try
{
robot = new Robot();
}
catch (Exception ex)
{
System.out.println(ex.toString());
}
scrRect = new Rectangle(x1, y1, width, height);
}
public BufferedImage captureScreen()
{
BufferedImage bufImg = null;
try
{
bufImg = robot.createScreenCapture(scrRect);
}
catch (Exception e)
{
System.out.println(e.toString());
}
return bufImg;
}
}
class ScreenCapture
{
/**
* @param args
*/
private Robot robot = null;
private Rectangle scrRect = null;
int x1,y1;
int width,high;
public ScreenCapture()
{
try
{
robot = new Robot();
}
catch (Exception ex)
{
System.out.println(ex.toString());
}
scrRect = new Rectangle(x1, y1, width, height);
}
public BufferedImage captureScreen()
{
BufferedImage bufImg = null;
try
{
bufImg = robot.createScreenCapture(scrRect);
}
catch (Exception e)
{
System.out.println(e.toString());
}
return bufImg;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询