Note that there are some explanatory texts on larger screens.

plurals
  1. POsaving bitmap data to a file
    primarykey
    data
    text
    <p>i'm trying to take screenshot with python using only ctypes.</p> <p>i get stuck after the bitblt. do anyone have a code which saves the bitmap object into a file with ctypes in python?</p> <p>this is the code i wrote so far:</p> <pre><code>import ctypes from ctypes import * #Constants SM_CXSCREEN = 0 SM_CYSCREEN = 1 SRCCOPY = 0xCC0020 user32 = ctypes.windll.user32 gdi32 = ctypes.windll.gdi32 class BITMAPINFOHEADER(ctypes.Structure): _fields_ = [ ('biSize', ctypes.c_uint32), ('biWidth', ctypes.c_int), ('biHeight', ctypes.c_int), ('biPlanes', ctypes.c_short), ('biBitCount', ctypes.c_short), ('biCompression', ctypes.c_uint32), ('biSizeImage', ctypes.c_uint32), ('biXPelsPerMeter', ctypes.c_long), ('biYPelsPerMeter', ctypes.c_long), ('biClrUsed', ctypes.c_uint32), ('biClrImportant', ctypes.c_uint32) ] class BITMAPINFO(ctypes.Structure): _fields_ = [ ('bmiHeader', BITMAPINFOHEADER), ('bmiColors', ctypes.c_ulong * 3) ] hDesktopWnd = user32.GetDesktopWindow() WinDC = user32.GetDC (hDesktopWnd) CopyDC = gdi32.CreateCompatibleDC (WinDC) hBitmap = gdi32.CreateCompatibleBitmap (WinDC, 1000, 1000) gdi32.SelectObject (CopyDC, hBitmap) gdi32.BitBlt(CopyDC, 0,0, 1000, 1000, WinDC, 0, 0, SRCCOPY); </code></pre> <p>i know that the next step will be somthing like:</p> <pre><code>lpbi = BITMAPINFO() ctypes.memset(ctypes.byref(lpbi), 0x00, ctypes.sizeof(lpbi)) lpbi.bmiHeader.biSize = ctypes.sizeof(BITMAPINFOHEADER) gdi32.SelectObject (CopyDC, hBitmap) ... </code></pre> <p>but it sucked and didn't work. please help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload