Beispiel #1
0
 def Screenshot(self):
     ########################
     # Usadas en Screenshot #
     ########################
     from time import sleep
     from win32gui import GetDesktopWindow, GetWindowDC
     from win32ui import CreateDCFromHandle, CreateBitmap
     from win32con import SRCCOPY, SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN, SM_XVIRTUALSCREEN, SM_YVIRTUALSCREEN
     from win32api import GetSystemMetrics, GetUserName
     from time import strftime
     print "Tomando Pantallazo"
     # Toma 4 pantallazos
     # Cada pantallazo lo llama pantallazo1 , 2 ,3 o 4
     # Lo hace cada 2 segundos
     t = strftime("%Y-%H%M%S")
     hwin = GetDesktopWindow()
     width = GetSystemMetrics(SM_CXVIRTUALSCREEN)
     height = GetSystemMetrics(SM_CYVIRTUALSCREEN)
     left = GetSystemMetrics(SM_XVIRTUALSCREEN)
     top = GetSystemMetrics(SM_YVIRTUALSCREEN)
     hwindc = GetWindowDC(hwin)
     srcdc = CreateDCFromHandle(hwindc)
     memdc = srcdc.CreateCompatibleDC()
     bmp = CreateBitmap()
     bmp.CreateCompatibleBitmap(srcdc, width, height)
     memdc.SelectObject(bmp)
     memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), SRCCOPY)
     bmp.SaveBitmapFile(
         memdc, "C:\\Users\\" + GetUserName() +
         "\\Downloads\\test\\screen" + t + ".bmp")
Beispiel #2
0
    def _capture(self):
        # make sure the process is DPI aware, otherwise the image
        # is only a part of the full monitor content
        # (necessary only on Win 8.1+)
        old_awareness = self._dpi_aware()
        self._set_dpi_aware(True)

        # get width and height of current monitor
        width = GetSystemMetrics(SM_CXVIRTUALSCREEN)
        height = GetSystemMetrics(SM_CYVIRTUALSCREEN)

        # get 'desktop' window handle
        handle_desktop = GetDesktopWindow()

        # get window graphic context handle
        handle_context = GetWindowDC(handle_desktop)

        # create device context
        dev_ctx = CreateDCFromHandle(handle_context)

        # create destination for original device context
        dest_ctx = dev_ctx.CreateCompatibleDC()

        # create bitmap compatible with desktop window device
        bmp = CreateBitmap()
        bmp.CreateCompatibleBitmap(dev_ctx, width, height)

        # select bitmap into destination device
        dest_ctx.SelectObject(bmp)

        # populate selected bitmap in destination device
        dest_ctx.BitBlt(
            (0, 0),  # start point (x, y)
            (width, height),  # size of rectangle
            dev_ctx,
            (  # source device
                GetSystemMetrics(SM_XVIRTUALSCREEN),
                GetSystemMetrics(SM_YVIRTUALSCREEN)
            ),  # source rectangle, can be different monitor
            SRCCOPY  # copy directly without filters
        )

        # save bitmap to file
        bmp.SaveBitmapFile(dest_ctx, self.file_path)

        # return to the original state
        self._set_dpi_aware(old_awareness)
Beispiel #3
0
 def ScreenShot(self):
     """
     截图 网上找的代码直接复制修改的
     后面加了释放资源代码,网上找的
     """
     hwndDC = GetWindowDC(self.mHwnd)
     mfcDC = CreateDCFromHandle(hwndDC)
     saveDC = mfcDC.CreateCompatibleDC()
     saveBitMap = CreateBitmap()
     saveBitMap.CreateCompatibleBitmap(mfcDC, self.mWindowWidth,
                                       self.mWindowHeight)
     saveDC.SelectObject(saveBitMap)
     saveDC.BitBlt((0, 0), (self.mWindowWidth, self.mWindowHeight), mfcDC,
                   (0, 0), SRCCOPY)
     saveBitMap.SaveBitmapFile(saveDC, self.mScreenShotFileName)
     self.mImageSrc = aircv.imread(self.mScreenShotFileName)
     # release
     DeleteObject(saveBitMap.GetHandle())
     mfcDC.DeleteDC()
     saveDC.DeleteDC()
     ReleaseDC(self.mHwnd, hwndDC)
Beispiel #4
0
def get_screenshot():
    hdesktop = GetDesktopWindow()

    width = GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)
    height = GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)
    left = GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)
    top = GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)

    hdc = GetWindowDC(hdesktop)
    source_dc = CreateDCFromHandle(hdc)
    target_dc = source_dc.CreateCompatibleDC()

    bmp = CreateBitmap()
    bmp.CreateCompatibleBitmap(source_dc, width, height)

    target_dc.SelectObject(bmp)
    target_dc.BitBlt((0, 0), (width, height), source_dc, (left, top),
                     win32con.SRCCOPY)

    tmp = tempfile.NamedTemporaryFile(suffix='.bmp')
    bmp.SaveBitmapFile(target_dc, tmp.name)
    return tmp