我可以使用下面的代碼截取前景圖像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有什么區(qū)別?
1 回答

縹緲止盈
TA貢獻2041條經驗 獲得超4個贊
客戶坐標指定客戶區(qū)的左上角和右下角。因為客戶坐標是相對于窗口客戶區(qū)的左上角的,所以左上角的坐標是(0,0)。
這是一個相對坐標系。
您還應該調用ClientToScreen將客戶端坐標轉換為屏幕坐標。
注意ClientToScreen
只接收POINT
(不是a RECT
)的參數,你可以在這里POINT
找到類。
編輯:
GetWindowRect
將獲得“額外”尺寸。但是,GetClientRect
完全不包括它(以及其他額外信息,如標題欄、窗口邊框等)。
添加回答
舉報
0/150
提交
取消