本文整理汇总了Python中win32ui.CreateBitmap方法的典型用法代码示例。如果您正苦于以下问题:Python win32ui.CreateBitmap方法的具体用法?Python win32ui.CreateBitmap怎么用?Python win32ui.CreateBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块win32ui的用法示例。
在下文中一共展示了win32ui.CreateBitmap方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_bitmap
点赞 5
# 需要导入模块: import win32ui [as 别名]
# 或者: from win32ui import CreateBitmap [as 别名]
def get_bitmap() -> image:
"""Get and return a bitmap of the Window."""
left, top, right, bot = win32gui.GetWindowRect(Window.id)
w = right - left
h = bot - top
hwnd_dc = win32gui.GetWindowDC(Window.id)
mfc_dc = win32ui.CreateDCFromHandle(hwnd_dc)
save_dc = mfc_dc.CreateCompatibleDC()
save_bitmap = win32ui.CreateBitmap()
save_bitmap.CreateCompatibleBitmap(mfc_dc, w, h)
save_dc.SelectObject(save_bitmap)
windll.user32.PrintWindow(Window.id, save_dc.GetSafeHdc(), 0)
bmpinfo = save_bitmap.GetInfo()
bmpstr = save_bitmap.GetBitmapBits(True)
# This creates an Image object from Pillow
bmp = image.frombuffer('RGB',
(bmpinfo['bmWidth'],
bmpinfo['bmHeight']),
bmpstr, 'raw', 'BGRX', 0, 1)
win32gui.DeleteObject(save_bitmap.GetHandle())
save_dc.DeleteDC()
mfc_dc.DeleteDC()
win32gui.ReleaseDC(Window.id, hwnd_dc)
# bmp.save("asdf.png")
return bmp
开发者ID:kujan,项目名称:NGU-scripts,代码行数:29,
示例2: GetScreenImg
点赞 5
# 需要导入模块: import win32ui [as 别名]
# 或者: from win32ui import CreateBitmap [as 别名]
def GetScreenImg(self):
'''
Gets the screen of the window referenced by self.hwnd
'''
if self.hwnd is None:
raise Exception("HWND is none. HWND not called or invalid window name provided.")
self.l, self.t, self.r, self.b = win32gui.GetWindowRect(self.hwnd)
#Remove border around window (8 pixels on each side)
#Remove 4 extra pixels from left and right 16 + 8 = 24
w = self.r - self.l - self.br - self.bl
#Remove border on top and bottom (31 on top 8 on bottom)
#Remove 12 extra pixels from bottom 39 + 12 = 51
h = self.b - self.t - self.bt - self.bb
wDC = win32gui.GetWindowDC(self.hwnd)
dcObj = win32ui.CreateDCFromHandle(wDC)
cDC = dcObj.CreateCompatibleDC()
dataBitMap = win32ui.CreateBitmap()
dataBitMap.CreateCompatibleBitmap(dcObj, w, h)
cDC.SelectObject(dataBitMap)
#First 2 tuples are top-left and bottom-right of destination
#Third tuple is the start position in source
cDC.BitBlt((0,0), (w, h), dcObj, (self.bl, self.bt), win32con.SRCCOPY)
bmInfo = dataBitMap.GetInfo()
im = np.frombuffer(dataBitMap.GetBitmapBits(True), dtype = np.uint8)
dcObj.DeleteDC()
cDC.DeleteDC()
win32gui.ReleaseDC(self.hwnd, wDC)
win32gui.DeleteObject(dataBitMap.GetHandle())
#Bitmap has 4 channels like: BGRA. Discard Alpha and flip order to RGB
#31 pixels from border on top, 8 on bottom
#8 pixels from border on the left and 8 on right
#Remove 1 additional pixel from left and right so size is 1278 | 9
#Remove 14 additional pixels from bottom so size is 786 | 6
#return im.reshape(bmInfo['bmHeight'], bmInfo