螢屏截圖再切一塊下來這個沒問題。
但是我想視窗不在前端,且是模擬器視窗的截圖就行了。
視窗類是qt5qwindowicon
網上找到的方法用了。第二句結果為NULL
public static Bitmap GetWindow(IntPtr hWnd)
{
IntPtr hscrdc = GetWindowDC(hWnd);
Control control = Control.FromHandle(hWnd);//這里的control為NULL了。其它的沒辦法執行下去。
IntPtr hbitmap = CreateCompatibleBitmap(hscrdc, control.Width, control.Height);
IntPtr hmemdc = CreateCompatibleDC(hscrdc);
SelectObject(hmemdc, hbitmap);
PrintWindow(hWnd, hmemdc, 0);
Bitmap bmp = Bitmap.FromHbitmap(hbitmap);
DeleteDC(hscrdc);//洗掉用過的物件
DeleteDC(hmemdc);//洗掉用過的物件
return bmp;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/69648.html
標籤:C#
