python deletedc_Python win32gui.GetWindowDC方法代碼示例

本文整理匯總了Python中win32gui.GetWindowDC方法的典型用法代碼示例。如果您正苦於以下問題:Python win32gui.GetWindowDC方法的具體用法?Python win32gui.GetWindowDC怎麽用?Python win32gui.GetWindowDC使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在模塊win32gui的用法示例。

在下文中一共展示了win32gui.GetWindowDC方法的18個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。

示例1: WindowDraw

?點讚 6

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [as 別名]

def WindowDraw(self, rect):

'''

Draws a rectangle to the window

'''

if self.hwnd is None:

return

#raise Exception("HWND is none. HWND not called or invalid window name provided.")

wDC = win32gui.GetWindowDC(self.hwnd)

dcObj = win32ui.CreateDCFromHandle(wDC)

#Set background mode to transparent

#dcObj.SetBkColor(0x12345)

#dcObj.SetBkMode(0)

dcObj.Rectangle(rect)

# Free Resources

dcObj.DeleteDC()

win32gui.ReleaseDC(self.hwnd, wDC)

開發者ID:nicholastoddsmith,項目名稱:poeai,代碼行數:18,

示例2: set_props

?點讚 6

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [as 別名]

def set_props( self, window = None, **kwargs ):

if window and self.roi:

win32gui.InvalidateRect( window.window_handle,

self.roi, True )

for key in ('text','rect','style','font','color'):

if key in kwargs:

setter = '_set_' + key

if hasattr( self, setter ):

getattr( self, setter )( kwargs[ key ] )

else:

setattr( self, key, kwargs[ key ] )

if window:

hdc = win32gui.GetWindowDC( window.window_handle )

roi = self.calc_roi( hdc )

win32gui.ReleaseDC( window.window_handle, hdc )

win32gui.InvalidateRect( window.window_handle,

roi, True )

開發者ID:mailpile,項目名稱:gui-o-matic,代碼行數:22,

示例3: get_bitmap

?點讚 5

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [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,

示例4: get_pixel_color

?點讚 5

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [as 別名]

def get_pixel_color(x :int, y :int, debug :bool =False) -> str:

"""Get the color of selected pixel in HEX."""

dc = win32gui.GetWindowDC(Window.id)

rgba = win32gui.GetPixel(dc, x + 8 + Window.x, y + 8 + Window.y)

win32gui.ReleaseDC(Window.id, dc)

r = rgba & 0xff

g = rgba >> 8 & 0xff

b = rgba >> 16 & 0xff

if debug: print(Inputs.rgb_to_hex((r, g, b)))

return Inputs.rgb_to_hex((r, g, b))

開發者ID:kujan,項目名稱:NGU-scripts,代碼行數:14,

示例5: GetScreenImg

?點讚 5

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [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,

示例6: grab_screen

?點讚 5

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [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,

示例7: grab_screen

?點讚 5

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [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,

示例8: grab_screen

?點讚 5

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [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,

示例9: shot

?點讚 5

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [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,

示例10: __init_screen_handles

?點讚 5

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [as 別名]

def __init_screen_handles(self):

# opengl windows cannot get from it's hwnd, so we use the screen

hwnd = win32gui.GetDesktopWindow()

# get screen size and offset

left, top, right, bottom = self.rect

width, height = right-left, bottom-top

# the device context of the window

hdcwin = win32gui.GetWindowDC(hwnd)

# make a temporary dc

hdcmem = win32gui.CreateCompatibleDC(hdcwin)

# make a temporary bitmap in memory, this is a PyHANDLE object

hbmp = win32gui.CreateCompatibleBitmap(hdcwin, width, height)

# select bitmap for temporary dc

win32gui.SelectObject(hdcmem, hbmp)

# check the bitmap object infomation

bmp = win32gui.GetObject(hbmp)

bi = BITMAPINFOHEADER()

bi.biSize = ctypes.sizeof(BITMAPINFOHEADER)

bi.biWidth = bmp.bmWidth

bi.biHeight = bmp.bmHeight

bi.biPlanes = bmp.bmPlanes

bi.biBitCount = bmp.bmBitsPixel

bi.biCompression = 0 # BI_RGB

bi.biSizeImage = 0

bi.biXPelsPerMeter = 0

bi.biYPelsPerMeter = 0

bi.biClrUsed = 0

bi.biClrImportant = 0

# calculate total size for bits

pixel = bmp.bmBitsPixel

size = ((bmp.bmWidth * pixel + pixel - 1)/pixel) * 4 * bmp.bmHeight

buf = (ctypes.c_char * size)()

self._hdcwin = hdcwin

self._hdcmem = hdcmem

self._bi = bi

self._hbmp = hbmp

self._buf = buf

開發者ID:NetEaseGame,項目名稱:ATX,代碼行數:40,

示例11: _set_icon_menu

?點讚 5

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [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,

示例12: init_mem

?點讚 5

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [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,

示例13: take_png_screenshot

?點讚 5

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [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,

示例14: create_fonts

?點讚 5

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [as 別名]

def create_fonts( self ):

'''

Create all font objects

'''

self.known_fonts = {}

def handle_font( font_config, text_metric, font_type, param ):

#print font_config.lfFaceName

self.known_fonts[ font_config.lfFaceName ] = font_config

return True

hdc = win32gui.GetWindowDC( self.main_window.window_handle )

#print "=== begin availalbe fonts ==="

win32gui.EnumFontFamilies( hdc, None, handle_font, None )

#print "=== end available fonts ==="

# https://stackoverflow.com/questions/6057239/which-font-is-the-default-for-mfc-dialog-controls

self.non_client_metrics = win32gui.SystemParametersInfo( win32con.SPI_GETNONCLIENTMETRICS, None, 0 )

self.default_font = self.non_client_metrics[ 'lfMessageFont' ].lfFaceName

#print "Default font: " + self.default_font

keys = ( 'title', 'details', 'notification', 'splash', 'buttons' )

font_config = self.config.get( 'font_styles', {} )

self.fonts = { key: self.create_font( hdc, **font_config.get(key, {}) ) for key in keys }

if 'buttons' not in self.fonts:

self.fonts['buttons'] = win32gui.CreateFontIndirect( self.non_client_metrics[ 'lfMessageFont' ] )

win32gui.ReleaseDC( self.main_window.window_handle, hdc )

開發者ID:mailpile,項目名稱:gui-o-matic,代碼行數:30,

示例15: screenshot

?點讚 4

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [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,

示例16: screen

?點讚 4

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [as 別名]

def screen(self):

"""PIL Image of current window screen. (the window must be on the top)

reference: https://msdn.microsoft.com/en-us/library/dd183402(v=vs.85).aspx"""

# opengl windows cannot get from it's hwnd, so we use the screen

hwnd = win32gui.GetDesktopWindow()

# get window size and offset

left, top, right, bottom = self.rect

width, height = right-left, bottom-top

# the device context of the window

hdcwin = win32gui.GetWindowDC(hwnd)

# make a temporary dc

hdcmem = win32gui.CreateCompatibleDC(hdcwin)

# make a temporary bitmap in memory, this is a PyHANDLE object

hbmp = win32gui.CreateCompatibleBitmap(hdcwin, width, height)

# select bitmap for temporary dc

win32gui.SelectObject(hdcmem, hbmp)

# copy bits to temporary dc

win32gui.BitBlt(hdcmem, 0, 0, width, height,

hdcwin, left, top, win32con.SRCCOPY)

# check the bitmap object infomation

bmp = win32gui.GetObject(hbmp)

bi = BITMAPINFOHEADER()

bi.biSize = ctypes.sizeof(BITMAPINFOHEADER)

bi.biWidth = bmp.bmWidth

bi.biHeight = bmp.bmHeight

bi.biPlanes = bmp.bmPlanes

bi.biBitCount = bmp.bmBitsPixel

bi.biCompression = 0 # BI_RGB

bi.biSizeImage = 0

bi.biXPelsPerMeter = 0

bi.biYPelsPerMeter = 0

bi.biClrUsed = 0

bi.biClrImportant = 0

# calculate total size for bits

pixel = bmp.bmBitsPixel

size = ((bmp.bmWidth * pixel + pixel - 1)/pixel) * 4 * bmp.bmHeight

buf = (ctypes.c_char * size)()

# read bits into buffer

windll.gdi32.GetDIBits(hdcmem, hbmp.handle, 0, bmp.bmHeight, buf, ctypes.byref(bi), win32con.DIB_RGB_COLORS)

# make a PIL Image

img = Image.frombuffer('RGB', (bmp.bmWidth, bmp.bmHeight), buf, 'raw', 'BGRX', 0, 1)

img = img.transpose(Image.FLIP_TOP_BOTTOM)

# cleanup

win32gui.DeleteObject(hbmp)

win32gui.DeleteObject(hdcmem)

win32gui.ReleaseDC(hwnd, hdcwin)

return img

開發者ID:NetEaseGame,項目名稱:ATX,代碼行數:57,

示例17: window_part_shot

?點讚 4

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [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,

示例18: layout_displays

?點讚 4

?

# 需要導入模塊: import win32gui [as 別名]

# 或者: from win32gui import GetWindowDC [as 別名]

def layout_displays( self, padding = 10 ):

'''

layout displays top-to-bottom, placing notification text after

TODO: use 2 passes to split v-spacing

'''

region = self.main_window.get_client_region()

region = (region[0] + padding,

region[1] + padding,

region[2] - 2 * padding,

min(region[3] - 2 * padding, self.button_region[1]))

hdc = win32gui.GetWindowDC( self.main_window.window_handle )

def display_keys():

items = self.config['main_window']['status_displays']

return map( lambda item: item['id'], items )

rect = region

for key in display_keys():

display = self.displays[ key ]

detail_text = display.details.text

detail_lines = max( detail_text.count( '\n' ), 2 )

display.details.set_props( text = 'placeholder\n' * detail_lines )

rect = display.layout( hdc, rect, padding )

display.details.set_props( text = detail_text )

if len( self.displays ) > 1:

v_spacing = min( (rect[3] - rect[1]) / (len( self.displays ) -1), padding * 2 )

else:

v_spacing = 0

rect = region

for key in display_keys():

display = self.displays[ key ]

detail_text = display.details.text

detail_lines = max( detail_text.count( '\n' ), 2 )

display.details.set_props( text = 'placeholder\n' * detail_lines )

rect = display.layout( hdc, rect, padding )

display.details.set_props( text = detail_text )

rect = (rect[0],

rect[1] + v_spacing,

rect[2],

rect[3])

#self.notification_text.rect = rect

win32gui.ReleaseDC( self.main_window.window_handle, hdc )

開發者ID:mailpile,項目名稱:gui-o-matic,代碼行數:52,

注:本文中的win32gui.GetWindowDC方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。