Esempio n. 1
0
File: pvz.py Progetto: NEUGWB/pvz.py
def ScreenShot(dpath): 
    hwndDC = win32gui.GetDC(hwnd)
    memDc = win32gui.CreateCompatibleDC(hwndDC)
    hBmp   = win32gui.CreateCompatibleBitmap(hwndDC, 800, 600)
    oldBmp = win32gui.SelectObject(memDc, hBmp)

    #win32gui.BitBlt(memDc,0,0,800,600,hwndDC,0,0,win32con.SRCCOPY);
    ctypes.windll.user32.PrintWindow(hwnd, memDc, 1)
    
    filename = TimeStamp()
    bmpname = dpath + filename + '.bmp'

    saveBitMap = win32ui.CreateBitmapFromHandle(hBmp)
    saveDC = win32ui.CreateDCFromHandle(memDc)
    saveBitMap.SaveBitmapFile(saveDC, bmpname)

    win32gui.SelectObject(memDc, oldBmp)
    win32gui.DeleteObject(memDc)
    win32gui.DeleteObject(hBmp)
    win32gui.ReleaseDC(hwnd, hwndDC)
    
    jpgname = bmpname[:-4]+".jpg"
    Image.open(bmpname).save(jpgname)
    SafeDelete(bmpname)
    
    screenList.append(jpgname)
    if len(screenList) > 300:
        SafeDelete(screenList[0])
        del(screenList[0])
Esempio n. 2
0
 def createDDB(self, img, w=0, h=0):
     if img < 0: return
     if w == 0 or h == 0:
         w, h, d = self.size(img)
     hbmp, hpal = self.lib.image_create_ddb(img, w, h)
     import win32ui
     bmp = win32ui.CreateBitmapFromHandle(hbmp)
     win32ui.GetWin32Sdk().DeleteObject(hpal)
     return bmp
Esempio n. 3
0
 def createDDB(self,img, w = 0, h = 0):
     if img is None:
         return None
     if w==0 or h==0:
         w, h, d = img.image_dimensions_get()
     hbmp, hpal = img.image_create_ddb(w, h)
     import win32ui
     bmp = win32ui.CreateBitmapFromHandle(hbmp)
     win32ui.GetWin32Sdk().DeleteObject(hpal)
     return bmp
Esempio n. 4
0
 def __init__(self, width, height, config=None, share_group=None, **kwds):
     print "GLPixmap:", width, height, kwds  ###
     config = GLConfig._from_args(config, kwds)
     pyhdc = gui.CreateCompatibleDC(0)
     dc = ui.CreateDCFromHandle(pyhdc)
     hdc = dc.GetSafeHdc()
     hbm = gui.CreateCompatibleBitmap(hdc, width, height)
     bm = ui.CreateBitmapFromHandle(hbm)
     dc.SelectObject(bm)
     self._win_dc = dc
     self._win_hbm = hbm
     self._win_bm = bm
     GLContext.__init__(self, share_group, config, hdc, 'pixmap')
     self._with_context(hdc, self._init_context)
     print "GLPixmap: done"  ###
Esempio n. 5
0
    def _take_screenshot_with_native_api(self, x, y, w, h, hwnd):
        if hwnd is None:
            scr_hdc = win32gui.CreateDC('DISPLAY', None, None)
        else:
            scr_hdc = win32gui.GetDC(hwnd)
        mem_hdc = win32gui.CreateCompatibleDC(scr_hdc)
        new_bitmap_h = win32gui.CreateCompatibleBitmap(scr_hdc, w, h)
        win32gui.SelectObject(
            mem_hdc, new_bitmap_h
        )  # Returns 'old_bitmap_h'. It will be deleted automatically.

        win32gui.BitBlt(mem_hdc, 0, 0, w, h, scr_hdc, x, y, win32con.SRCCOPY)

        bmp = win32ui.CreateBitmapFromHandle(new_bitmap_h)
        bmp_info = bmp.GetInfo()
        if bmp_info['bmHeight'] != h or bmp_info['bmWidth'] != w:
            raise FailExit('bmp_info = {bmp}, but (w, h) = ({w}, {h})'.format(
                bmp=bmp_info, width=w, height=h))
        if bmp_info['bmType'] != 0 or bmp_info['bmPlanes'] != 1:
            raise FailExit(
                'bmp_info = {bmp}: bmType !=0 or bmPlanes != 1'.format(
                    bmp=str(bmp_info)))
        if bmp_info['bmBitsPixel'] % 8 != 0:
            raise FailExit(
                'bmp_info = {bmp}: bmBitsPixel mod. 8 is not zero'.format(
                    bmp=str(bmp_info)))

        bmp_arr = list(bmp.GetBitmapBits())

        if len(bmp_arr) == w * h * 4:
            del bmp_arr[3::
                        4]  # Delete alpha channel. TODO: Is it fast enough???
        elif len(bmp_arr) != w * h * 3:
            raise FailExit('An error occurred while read bitmap bits')

        result = np.array(bmp_arr, dtype=np.uint8).reshape((h, w, 3))

        win32gui.DeleteDC(mem_hdc)
        win32gui.DeleteObject(new_bitmap_h)

        if not hwnd:
            win32gui.DeleteDC(scr_hdc)
        else:
            win32gui.ReleaseDC(hwnd, scr_hdc)

        return result
Esempio n. 6
0
def get_color(pos):

    hdc_screen = win32gui.CreateDC("DISPLAY", "", None)

    hmem_dc = win32gui.CreateCompatibleDC(hdc_screen)

    h_bitmap = win32gui.CreateCompatibleBitmap(hdc_screen, 1, 1)

    h_old_bitmap = win32gui.SelectObject(hmem_dc, h_bitmap)

    win32gui.BitBlt(hmem_dc, 0, 0, 1, 1, hdc_screen, pos[0], pos[1], win32con.SRCCOPY)  

    win32gui.DeleteDC(hdc_screen) 

    win32gui.DeleteDC(hmem_dc) 

    x = win32ui.CreateBitmapFromHandle(h_bitmap) 

    bits = x.GetBitmapBits(True)   

    return struct.unpack('I', bits)[0]