我可以使用下面的代码截取前景图像void startScreencapture(){ RECT dimensionsOfWindow = new RECT(); User32.INSTANCE.GetWindowRect(User32.INSTANCE.GetForegroundWindow(), dimensionsOfWindow );//now in the dimensionsOfWindow you have the dimensions Robot robot = new Robot(); buf = robot.createScreenCapture( dimensionsOfWindow.toRectangle() );}public interface User32 extends StdCallLibrary { User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class); HWND GetForegroundWindow(); // add this int GetWindowTextA(PointerType hWnd, byte[] lpString, int nMaxCount); public boolean GetWindowRect(HWND hWnd, RECT rect);}我得到如下前景截图如果您注意到,屏幕截图在窗口的边界处有一些额外的图像。我不希望我的屏幕截图中有额外的图像部分。是否有可能以某种方式操纵User32.INSTANCE.GetForegroundWindow()这样我就可以得到没有额外部分的屏幕截图?我觉得这个链接中的答案应该有效。WinApi中的GetClientRect和GetWindowRect有什么区别?
1 回答

缥缈止盈
TA贡献2041条经验 获得超4个赞
客户坐标指定客户区的左上角和右下角。因为客户坐标是相对于窗口客户区的左上角的,所以左上角的坐标是(0,0)。
这是一个相对坐标系。
您还应该调用ClientToScreen将客户端坐标转换为屏幕坐标。
注意ClientToScreen
只接收POINT
(不是a RECT
)的参数,你可以在这里POINT
找到类。
编辑:
GetWindowRect
将获得“额外”尺寸。但是,GetClientRect
完全不包括它(以及其他额外信息,如标题栏、窗口边框等)。
添加回答
举报
0/150
提交
取消