本文整理汇总了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['bmWidth'], 4)[31:-22, 9:-9, -2::-1]

#For 800x600 images:

#Remove 12 pixels from bottom + border

#Remove 4 pixels from left and right + border

return im.reshape(bmInfo['bmHeight'], bmInfo['bmWidth'], 4)[:, :, -2::-1]

开发者ID:nicholastoddsmith,项目名称:poeai,代码行数:40,

示例3: OnOpenDocument

​点赞 5

# 需要导入模块: import win32ui [as 别名]

# 或者: from win32ui import CreateBitmap [as 别名]

def OnOpenDocument(self, filename):

self.bitmap=win32ui.CreateBitmap()

# init data members

f = open(filename, 'rb')

try:

try:

self.bitmap.LoadBitmapFile(f)

except IOError:

win32ui.MessageBox("Could not load the bitmap from %s" % filename)

return 0

finally:

f.close()

self.size = self.bitmap.GetSize()

return 1

开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,

示例4: grab_screen

​点赞 5

# 需要导入模块: import win32ui [as 别名]

# 或者: from win32ui import CreateBitmap [as 别名]

def grab_screen(region=None):

hwin = win32gui.GetDesktopWindow()

if region:

left,top,x2,y2 = region

width = x2 - left + 1

height = y2 - top + 1

else:

width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)

height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)

left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)

top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)

hwindc = win32gui.GetWindowDC(hwin)

srcdc = win32ui.CreateDCFromHandle(hwindc)

memdc = srcdc.CreateCompatibleDC()

bmp = win32ui.CreateBitmap()

bmp.CreateCompatibleBitmap(srcdc, width, height)

memdc.SelectObject(bmp)

memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)

signedIntsArray = bmp.GetBitmapBits(True)

img = np.fromstring(signedIntsArray, dtype='uint8')

img.shape = (height,width,4)

srcdc.DeleteDC()

memdc.DeleteDC()

win32gui.ReleaseDC(hwin, hwindc)

win32gui.DeleteObject(bmp.GetHandle())

return cv2.cvtColor(img, cv2.COLOR_BGRA2RGB)

开发者ID:Sentdex,项目名称:pygta5,代码行数:34,

示例5: grab_screen

​点赞 5

# 需要导入模块: import win32ui [as 别名]

# 或者: from win32ui import CreateBitmap [as 别名]

def grab_screen(region=None):

hwin = win32gui.GetDesktopWindow()

if region:

left,top,x2,y2 = region

width = x2 - left + 1

height = y2 - top + 1

else:

width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)

height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)

left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)

top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)

hwindc = win32gui.GetWindowDC(hwin)

srcdc = win32ui.CreateDCFromHandle(hwindc)

memdc = srcdc.CreateCompatibleDC()

bmp = win32ui.CreateBitmap()

bmp.CreateCompatibleBitmap(srcdc, width, height)

memdc.SelectObject(bmp)

memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)

signedIntsArray = bmp.GetBitmapBits(True)

img = np.fromstring(signedIntsArray, dtype='uint8')

img.shape = (height,width,4)

srcdc.DeleteDC()

memdc.DeleteDC()

win32gui.ReleaseDC(hwin, hwindc)

win32gui.DeleteObject(bmp.GetHandle())

return cv2.cvtColor(img, cv2.COLOR_BGRA2RGB)

开发者ID:Sentdex,项目名称:pygta5,代码行数:32,

示例6: grab_screen

​点赞 5

# 需要导入模块: import win32ui [as 别名]

# 或者: from win32ui import CreateBitmap [as 别名]

def grab_screen(region=None):

hwin = win32gui.GetDesktopWindow()

if region:

left,top,x2,y2 = region

width = x2 - left + 1

height = y2 - top + 1

else:

width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)

height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)

left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)

top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)

hwindc = win32gui.GetWindowDC(hwin)

srcdc = win32ui.CreateDCFromHandle(hwindc)

memdc = srcdc.CreateCompatibleDC()

bmp = win32ui.CreateBitmap()

bmp.CreateCompatibleBitmap(srcdc, width, height)

memdc.SelectObject(bmp)

memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)

signedIntsArray = bmp.GetBitmapBits(True)

img = np.fromstring(signedIntsArray, dtype='uint8')

img.shape = (height,width,4)

srcdc.DeleteDC()

memdc.DeleteDC()

win32gui.ReleaseDC(hwin, hwindc)

win32gui.DeleteObject(bmp.GetHandle())

return cv2.cvtColor(img, cv2.COLOR_BGRA2RGB)

开发者ID:Sentdex,项目名称:pygta5,代码行数:35,

示例7: shot

​点赞 5

# 需要导入模块: import win32ui [as 别名]

# 或者: from win32ui import CreateBitmap [as 别名]

def shot(cls,name= 'playing.png'):

hwnd = win32gui.FindWindow(None, cls.processname)

# Change the line below depending on whether you want the whole window

# or just the client area.

left, top, right, bot = win32gui.GetClientRect(hwnd)

#left, top, right, bot = win32gui.GetWindowRect(hwnd)

w = right - left

h = bot - top

hwndDC = win32gui.GetWindowDC(hwnd)

mfcDC = win32ui.CreateDCFromHandle(hwndDC)

saveDC = mfcDC.CreateCompatibleDC()

saveBitMap = win32ui.CreateBitmap()

saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)

saveDC.SelectObject(saveBitMap)

# Change the line below depending on whether you want the whole window

# or just the client area.

#result = windll.user32.PrintWindow(hwnd, saveDC.GetSafeHdc(), 1)

result = windll.user32.PrintWindow(hwnd, saveDC.GetSafeHdc(), 0)

bmpinfo = saveBitMap.GetInfo()

bmpstr = saveBitMap.GetBitmapBits(True)

im = Image.frombuffer(

'RGB',

(bmpinfo['bmWidth'], bmpinfo['bmHeight']),

bmpstr, 'raw', 'BGRX', 0, 1)

win32gui.DeleteObject(saveBitMap.GetHandle())

saveDC.DeleteDC()

mfcDC.DeleteDC()

win32gui.ReleaseDC(hwnd, hwndDC)

if result == 1:

#PrintWindow Succeeded

im.save("playing.png")

开发者ID:Sunuba,项目名称:roc,代码行数:42,

示例8: _set_icon_menu

​点赞 5

# 需要导入模块: import win32ui [as 别名]

# 或者: from win32ui import CreateBitmap [as 别名]

def _set_icon_menu(self, icon):

"""Load icons into the tray items.

Got from https://stackoverflow.com/a/45890829.

"""

ico_x = win32api.GetSystemMetrics(win32con.SM_CXSMICON)

ico_y = win32api.GetSystemMetrics(win32con.SM_CYSMICON)

hIcon = win32gui.LoadImage(0, icon, win32con.IMAGE_ICON, ico_x, ico_y, win32con.LR_LOADFROMFILE)

hwndDC = win32gui.GetWindowDC(self.hwnd)

dc = win32ui.CreateDCFromHandle(hwndDC)

memDC = dc.CreateCompatibleDC()

iconBitmap = win32ui.CreateBitmap()

iconBitmap.CreateCompatibleBitmap(dc, ico_x, ico_y)

oldBmp = memDC.SelectObject(iconBitmap)

brush = win32gui.GetSysColorBrush(win32con.COLOR_MENU)

win32gui.FillRect(memDC.GetSafeHdc(), (0, 0, ico_x, ico_y), brush)

win32gui.DrawIconEx(memDC.GetSafeHdc(), 0, 0, hIcon, ico_x, ico_y, 0, 0, win32con.DI_NORMAL)

memDC.SelectObject(oldBmp)

memDC.DeleteDC()

win32gui.ReleaseDC(self.hwnd, hwndDC)

self.logger.debug('Set menu icon.')

return iconBitmap.GetHandle()

开发者ID:Peter92,项目名称:MouseTracks,代码行数:29,

示例9: init_mem

​点赞 5

# 需要导入模块: import win32ui [as 别名]

# 或者: from win32ui import CreateBitmap [as 别名]

def init_mem(self):

self.hwindc = win32gui.GetWindowDC(self.hwnd)

self.srcdc = win32ui.CreateDCFromHandle(self.hwindc)

self.memdc = self.srcdc.CreateCompatibleDC()

self.bmp = win32ui.CreateBitmap()

self.bmp.CreateCompatibleBitmap(

self.srcdc, self._client_w, self._client_h)

self.memdc.SelectObject(self.bmp)

开发者ID:AcademicDog,项目名称:onmyoji_bot,代码行数:10,

示例10: take_png_screenshot

​点赞 5

# 需要导入模块: import win32ui [as 别名]

# 或者: from win32ui import CreateBitmap [as 别名]

def take_png_screenshot(self):

if not self.win_handle:

raise Exception("Win handle is not valid for Steam")

# Crops the image from the desktop

left, top, right, bottom = win32gui.GetWindowRect(self.win_handle)

width = right - left

height = bottom - top

hwnd_dc = win32gui.GetWindowDC(self.win_handle)

# Get a bitmap

mfc_dc = win32ui.CreateDCFromHandle(hwnd_dc)

save_dc = mfc_dc.CreateCompatibleDC()

save_bit_map = win32ui.CreateBitmap()

save_bit_map.CreateCompatibleBitmap(mfc_dc, width, height)

save_dc.SelectObject(save_bit_map)

result = windll.user32.PrintWindow(self.win_handle, save_dc.GetSafeHdc(), 0x00000002)

if result != 1:

raise Exception("Failed to Steam screen")

bmp_info = save_bit_map.GetInfo()

bmp_raw = save_bit_map.GetBitmapBits(False)

img = np.array(bmp_raw, np.uint8).reshape(bmp_info['bmHeight'], bmp_info['bmWidth'], 4)

# Clean Up

win32gui.DeleteObject(save_bit_map.GetHandle())

save_dc.DeleteDC()

mfc_dc.DeleteDC()

win32gui.ReleaseDC(self.win_handle, hwnd_dc)

img_str = cv2.imencode('.jpg', img)[1].tostring()

return img_str

开发者ID:will7200,项目名称:Yugioh-bot,代码行数:29,

示例11: screenshot

​点赞 4

# 需要导入模块: import win32ui [as 别名]

# 或者: from win32ui import CreateBitmap [as 别名]

def screenshot(filename, hwnd=None):

"""

Take the screenshot of Windows app

Args:

filename: file name where to store the screenshot

hwnd:

Returns:

bitmap screenshot file

"""

# import ctypes

# user32 = ctypes.windll.user32

# user32.SetProcessDPIAware()

if hwnd is None:

"""all screens"""

hwnd = win32gui.GetDesktopWindow()

# get complete virtual screen including all monitors

w = win32api.GetSystemMetrics(SM_CXVIRTUALSCREEN)

h = win32api.GetSystemMetrics(SM_CYVIRTUALSCREEN)

x = win32api.GetSystemMetrics(SM_XVIRTUALSCREEN)

y = win32api.GetSystemMetrics(SM_YVIRTUALSCREEN)

else:

"""window"""

rect = win32gui.GetWindowRect(hwnd)

w = abs(rect[2] - rect[0])

h = abs(rect[3] - rect[1])

x, y = 0, 0

hwndDC = win32gui.GetWindowDC(hwnd)

mfcDC = win32ui.CreateDCFromHandle(hwndDC)

saveDC = mfcDC.CreateCompatibleDC()

saveBitMap = win32ui.CreateBitmap()

saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)

saveDC.SelectObject(saveBitMap)

saveDC.BitBlt((0, 0), (w, h), mfcDC, (x, y), win32con.SRCCOPY)

# saveBitMap.SaveBitmapFile(saveDC, filename)

bmpinfo = saveBitMap.GetInfo()

bmpstr = saveBitMap.GetBitmapBits(True)

pil_image = Image.frombuffer(

'RGB',

(bmpinfo['bmWidth'], bmpinfo['bmHeight']),

bmpstr, 'raw', 'BGRX', 0, 1)

cv2_image = pil_2_cv2(pil_image)

mfcDC.DeleteDC()

saveDC.DeleteDC()

win32gui.ReleaseDC(hwnd, hwndDC)

win32gui.DeleteObject(saveBitMap.GetHandle())

return cv2_image

开发者ID:AirtestProject,项目名称:Airtest,代码行数:53,

示例12: window_part_shot

​点赞 4

# 需要导入模块: import win32ui [as 别名]

# 或者: from win32ui import CreateBitmap [as 别名]

def window_part_shot(self, pos1, pos2, file_name=None, gray=0):

"""

窗口区域截图

:param pos1: (x,y) 截图区域的左上角坐标

:param pos2: (x,y) 截图区域的右下角坐标

:param file_name=None: 截图文件的保存路径

:param gray=0: 是否返回灰度图像,0:返回BGR彩色图像,其他:返回灰度黑白图像

:return: file_name为空则返回RGB数据

"""

w = pos2[0]-pos1[0]

h = pos2[1]-pos1[1]

hwindc = win32gui.GetWindowDC(self.hwnd)

srcdc = win32ui.CreateDCFromHandle(hwindc)

memdc = srcdc.CreateCompatibleDC()

bmp = win32ui.CreateBitmap()

bmp.CreateCompatibleBitmap(srcdc, w, h)

memdc.SelectObject(bmp)

if self.client == 0:

memdc.BitBlt((0, 0), (w, h), srcdc,

(pos1[0]+self._border_l, pos1[1]+self._border_t), win32con.SRCCOPY)

else:

memdc.BitBlt((0, -35), (w, h), srcdc,

(pos1[0]+self._border_l, pos1[1]+self._border_t), win32con.SRCCOPY)

if file_name != None:

bmp.SaveBitmapFile(memdc, file_name)

srcdc.DeleteDC()

memdc.DeleteDC()

win32gui.ReleaseDC(self.hwnd, hwindc)

win32gui.DeleteObject(bmp.GetHandle())

return

else:

signedIntsArray = bmp.GetBitmapBits(True)

img = np.fromstring(signedIntsArray, dtype='uint8')

img.shape = (h, w, 4)

srcdc.DeleteDC()

memdc.DeleteDC()

win32gui.ReleaseDC(self.hwnd, hwindc)

win32gui.DeleteObject(bmp.GetHandle())

#cv2.imshow("image", cv2.cvtColor(img, cv2.COLOR_BGRA2BGR))

# cv2.waitKey(0)

if gray == 0:

return cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)

else:

return cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY)

开发者ID:AcademicDog,项目名称:onmyoji_bot,代码行数:46,

注:本文中的win32ui.CreateBitmap方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。

python bitmap_Python win32ui.CreateBitmap方法代码示例相关推荐

  1. python dateformatter_Python dates.DateFormatter方法代码示例

    本文整理汇总了Python中matplotlib.dates.DateFormatter方法的典型用法代码示例.如果您正苦于以下问题:Python dates.DateFormatter方法的具体用法 ...

  2. python paperclip_Python pyplot.sca方法代码示例

    本文整理汇总了Python中matplotlib.pyplot.sca方法的典型用法代码示例.如果您正苦于以下问题:Python pyplot.sca方法的具体用法?Python pyplot.sca ...

  3. python fonttool_Python wx.Font方法代码示例

    本文整理汇总了Python中wx.Font方法的典型用法代码示例.如果您正苦于以下问题:Python wx.Font方法的具体用法?Python wx.Font怎么用?Python wx.Font使用 ...

  4. python res_Python models.resnet152方法代码示例

    本文整理汇总了Python中torchvision.models.resnet152方法的典型用法代码示例.如果您正苦于以下问题:Python models.resnet152方法的具体用法?Pyth ...

  5. python dropout_Python slim.dropout方法代码示例

    本文整理汇总了Python中tensorflow.contrib.slim.dropout方法的典型用法代码示例.如果您正苦于以下问题:Python slim.dropout方法的具体用法?Pytho ...

  6. python batch_size_Python config.batch_size方法代码示例

    本文整理汇总了Python中config.batch_size方法的典型用法代码示例.如果您正苦于以下问题:Python config.batch_size方法的具体用法?Python config. ...

  7. python pool_Python pool.Pool方法代码示例

    本文整理汇总了Python中multiprocessing.pool.Pool方法的典型用法代码示例.如果您正苦于以下问题:Python pool.Pool方法的具体用法?Python pool.Po ...

  8. python nextpow2_Python signal.hann方法代码示例

    本文整理汇总了Python中scipy.signal.hann方法的典型用法代码示例.如果您正苦于以下问题:Python signal.hann方法的具体用法?Python signal.hann怎么 ...

  9. python colormap_Python colors.LinearSegmentedColormap方法代码示例

    本文整理汇总了Python中matplotlib.colors.LinearSegmentedColormap方法的典型用法代码示例.如果您正苦于以下问题:Python colors.LinearSe ...

最新文章

  1. ZYNQ 的三种GPIO :MIO EMIO AXI_GPIO
  2. Juniper EX3400 Rescue configuration is not set
  3. 【组合数学】递推方程 ( 无重根递推方程求解实例 | 无重根下递推方程求解完整过程 )
  4. python numpy使用
  5. 脸盲分不清公司的程序员,同事教我一招,果然好用
  6. SQLSERVER2008--日志收缩 or 日志清理
  7. php 中访问常量,php 中的常量
  8. 容器技术Docker K8s 49 容器镜像服务(ACR)详解-概述
  9. mysql容灾备份和恢复_关于容灾备份和恢复
  10. python学习一点 快乐一点(2)乱序整数序列两数之和绝对值最小
  11. CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/win-64/curre
  12. protoc 插件-protoc-gen-grpc-gateway-gosdk
  13. Spring Cloud Gateway(十):网关过滤器工厂 GatewayFilterFactory
  14. python单词个数统计_Python 统计文本中单词的个数
  15. 知道创宇区块链安全实验室|二月安全事件总结与回顾
  16. 一键修复共享服务器权限问题
  17. Arduino项目专用的Beetle CM-32U4微控制器
  18. MySQL-数字格式化
  19. 联想g470散热_联想G470风扇声音很大怎么处理,散热也不好了。
  20. MAX31855热电偶转换器开发流程

热门文章

  1. 评价类问题——熵权法
  2. 【宿舍指纹锁---Arduino UNO (保姆级教程)】
  3. swift 视频截取一帧的几种实现方式
  4. redis用于php购物,PHP+redis实现的购物车单例类示例
  5. CSS单词换行and断词
  6. 给大家整理了一篇Python+selenium爬取智联招聘的职位信息
  7. 浅谈日本服务器与美国服务器对比
  8. 真正让我们成为局域网的不是那个墙,而是我们自己的肤浅
  9. python转移路径cd_改变当前路径 (cd)
  10. 跟我说回家,却还在外面鬼混,python程序员教你用微信给对方定位