def window_full_shot(hwnd, gray=0):
hwnd = get_hwnd(hwnd)[0]
print(hwnd)
print(win32gui.GetClassName(hwnd))
l, t, r, b = win32gui.GetWindowRect(hwnd)
h = b - t
w = r - l
hwindc = win32gui.GetWindowDC(hwnd)
srcdc = win32ui.CreateDCFromHandle(hwindc)
memdc = srcdc.CreateCompatibleDC()
bmp = win32ui.CreateBitmap()
bmp.CreateCompatibleBitmap(srcdc, w, h)
memdc.SelectObject(bmp)
memdc.BitBlt((0, 0), (w, h), srcdc, (0, 0), win32con.SRCCOPY)
signedIntsArray = bmp.GetBitmapBits(True)
img = np.fromstring(signedIntsArray, dtype='uint8')
img.shape = (h, w, 4)
print(type(img))
srcdc.DeleteDC()
memdc.DeleteDC()
win32gui.ReleaseDC(hwnd, hwindc)
win32gui.DeleteObject(bmp.GetHandle())
if gray == 0:
return cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
else:
return cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY)
我用这个代码拍了两个窗口,一个可以得到一个正确的img,另一个不行,就像那样。 the right codethe bad code
应用程序的框架,如电子应用程序,QT,WPF。。。将打印黑屏以响应
GetDC
或GetWindowDC
。你知道吗唯一的解决方法是确保目标应用程序可见,并在目标应用程序所在的特定坐标处拍摄桌面截图。
Windows GDI函数通常忽略alpha通道。但是如果您以32位检索屏幕截图,那么
关于代码示例(C++),请参阅:{{a1}GetDIBits
会将所有alpha值设置为255(至少在windows10中是这样)。你知道吗Python代码:
相关问题 更多 >
编程相关推荐