Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is the PIL's grabscreen source, Its does not accept any parameters, and Its grab the whole screen and convert it to bitmap.</p> <pre><code>PyImaging_GrabScreenWin32(PyObject* self, PyObject* args) { int width, height; HBITMAP bitmap; BITMAPCOREHEADER core; HDC screen, screen_copy; PyObject* buffer; /* step 1: create a memory DC large enough to hold the entire screen */ screen = CreateDC(";DISPLAY", NULL, NULL, NULL); screen_copy = CreateCompatibleDC(screen); width = GetDeviceCaps(screen, HORZRES); height = GetDeviceCaps(screen, VERTRES); bitmap = CreateCompatibleBitmap(screen, width, height); if (!bitmap) goto error; if (!SelectObject(screen_copy, bitmap)) goto error; /* step 2: copy bits into memory DC bitmap */ if (!BitBlt(screen_copy, 0, 0, width, height, screen, 0, 0, SRCCOPY)) goto error; /* step 3: extract bits from bitmap */ buffer = PyString_FromStringAndSize(NULL, height * ((width*3 + 3) &amp; -4)); if (!buffer) return NULL; core.bcSize = sizeof(core); core.bcWidth = width; core.bcHeight = height; core.bcPlanes = 1; core.bcBitCount = 24; if (!GetDIBits(screen_copy, bitmap, 0, height, PyString_AS_STRING(buffer), (BITMAPINFO*) &amp;core, DIB_RGB_COLORS)) goto error; DeleteObject(bitmap); DeleteDC(screen_copy); DeleteDC(screen); return Py_BuildValue("(ii)N", width, height, buffer); error: PyErr_SetString(PyExc_IOError, "screen grab failed"); DeleteDC(screen_copy); DeleteDC(screen); return NULL; } </code></pre> <p>So, when I just go a little deep, found C approach is good</p> <p><a href="http://msdn.microsoft.com/en-us/library/dd144909(VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/dd144909(VS.85).aspx</a></p> <p>And Python has ctypes, so here is my approach using ctypes (in Windows 10, <code>winnt</code> has been replaced with <code>Windows</code>):</p> <pre><code>&gt;&gt;&gt; from ctypes import * &gt;&gt;&gt; user= windll.LoadLibrary("c:\\winnt\\system32\\user32.dll") #I am in windows 2000, may be yours will be windows &gt;&gt;&gt; h = user.GetDC(0) &gt;&gt;&gt; gdi= windll.LoadLibrary("c:\\winnt\\system32\\gdi32.dll") &gt;&gt;&gt; gdi.GetPixel(h,1023,767) 16777215 #I believe its white color of RGB or BGR value, #FFFFFF (according to msdn it should be RGB) &gt;&gt;&gt; gdi.GetPixel(h,1024,767) -1 #because my screen is only 1024x768 </code></pre> <p>You could write a wrapper for function GetPixel like this</p> <pre><code>from ctypes import windll dc= windll.user32.GetDC(0) def getpixel(x,y): return windll.gdi32.GetPixel(dc,x,y) </code></pre> <p>Then you can use like <code>getpixel(0,0)</code>, <code>getpixel(100,0)</code>, etc...</p> <p><s>PS: Mine is Windows 2000, so I put <code>winnt</code> in the path, you may need to change it to <code>windows</code> or you chould completely remove path, just using <code>user32.dll</code> and <code>gdi32.dll</code> should work too.</s></p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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