In Button点击我已经实现了代码,当我第一次单击按钮时,它会得到x,y位置值,当我第二次单击该按钮时,它将获得x1,y1值并捕获图像。但不知何故,它还在原始图片上添加了黑色背景。我怎样才能避免这种情况?如何摆脱用Robot拍摄的图像上的黑色背景?
Toolkit tool = Toolkit.getDefaultToolkit();
c++;
Dimension d = tool.getScreenSize();
if(c==1)
{
x = MouseInfo.getPointerInfo().getLocation().x;
y = MouseInfo.getPointerInfo().getLocation().y;
}
if(c==2)
{
int x1= MouseInfo.getPointerInfo().getLocation().x;
int y1= MouseInfo.getPointerInfo().getLocation().y;
Rectangle rect = new Rectangle(x,y,x1,y1);
Robot robot = new Robot();
String J="Screen";
J=J+""+i;
//*************
String ext = ".jpg";
String path = loc+J+ ext;
File f = new File(path);
i++;
Thread t1 = new Thread();
t1.sleep(100);
BufferedImage img = robot.createScreenCapture(rect);
// img.createGraphics();
ImageIO.write(img,"jpeg",f);
tool.beep();
c=0;
x=0;
y=0;
x1=0;
y1=0;
}
我部分格式化你的代码,但请你花一些时间,使它看起来有点整洁。 – jjnguy 2011-05-25 14:36:54
谢谢jjnguy,我确定。 – jcrshankar 2011-05-25 14:42:45
看到我的新答案。我想我找到了你的问题。 – jjnguy 2011-05-25 15:41:39