例如,我正在拍摄一小部分桌面的屏幕截图(假设在拍摄屏幕时无法保存坐标)。接下来,拍摄全屏幕截图。如何在大屏幕截图中找到小屏幕截图的位置?
这在Java中是否可行?
public void RobotScreenCoordinateFinder()
{
Robot robot = new Robot();
robot.createScreenCapture(screenRect);
}
答案 0 :(得分:1)
我的想法是使用它:
BufferedImage screen=robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));c
BufferedImage capture=robot.createScreenCapture(screenRect);//assuming that screenRect is your capture
boolean screenMatches=false;
int screenX=0;
int screenY=0;
for(int i=0;i<screen.getWidth()-capture.getWidth();i++)
{
for(int j=0;j<screen.getHeight()-capture.getHeight();j++)
{
boolean matches=true;
for(int x=0;x<capture.getWidth();x++)
{
for(int y=0;y<capture.getHeight();y++)
{
if(screen.getRGB(i+x,j+y)!=capture.getRGB(x,y))
{
matches=false;
break;
}
}
if(!matches)break;
}
if(matches)
{
screenMatches=true;
screenX=i;
screenY=j;
break;
}
}
if(screenMatches)break;
}
//now if the capture is in the screen, screenMatches is true and the coordinate of the left up corner is stored in screenX and screenY
if(screenMatches)
{
System.out.println("Found match with coordinates "+screenX+","+screenY);
}