def screen(self):
"""PIL Image of current window screen.
reference: https://msdn.microsoft.com/en-us/library/dd183402(v=vs.85).aspx"""
hwnd = win32gui.GetDesktopWindow()
left, top, right, bottom = self.rect
width, height = right-left, bottom-top
# copy bits to temporary dc
win32gui.BitBlt(self._hdcmem, 0, 0, width, height,
self._hdcwin, left, top, win32con.SRCCOPY)
# read bits into buffer
windll.gdi32.GetDIBits(self._hdcmem, self._hbmp.handle, 0, height, self._buf, ctypes.byref(self._bi), win32con.DIB_RGB_COLORS)
# make a PIL Image
img = Image.frombuffer('RGB', (width, height), self._buf, 'raw', 'BGRX', 0, 1)
img = img.transpose(Image.FLIP_TOP_BOTTOM)
return img
评论列表
文章目录