我可以使用下面的代码截取前景图像
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有什么区别?
跃然一笑
缥缈止盈
随时随地看视频慕课网APP
相关分类