[python-win32] screen capture and win32gui.GetDesktopWindow()

Ray Schumacher rays at blue-cove.com
Fri Dec 8 02:05:31 CET 2006


Upon further tries, I can get handles, DCs, and/or Win32 BMPs from 
the desktop, but I can't get to a DIB from there.

Can someone outline the general process that might be required?
Ie.,
get window handle
create in/out DCs
select bmp to outDC
blit inDC data

I tried emulating a nice IronPython example:
http://www.voidspace.org.uk/python/weblog/arch_d7_2006_10_28.shtml
but,

hdcSrc = win32gui.GetWindowDC(win32gui.GetDesktopWindow())
hdcDestH = 
win32ui.CreateDCFromHandle(win32gui.GetDesktopWindow()      hdcDest = 
win32gui.CreateCompatibleDC(hdcSrc)
hBitmap = win32gui.CreateCompatibleBitmap(hdcSrc, 1024, 768)
win32gui.SelectObject(hdcDest, hBitmap)
hdcDestH.BitBlt((0, 0), (1024, 768), hdcSrc, (0, 0), 0x00CC0020)

fails with "TypeError: The 'O' param must be a PyCDC object". So, how 
to make the DCs cooperate?


myHdc = win32gui.GetDC(dtwnd)
win_sz = win32gui.GetClientRect(dtwnd)
myDC = win32ui.CreateDC()
myMemDC = myDC.CreateCompatibleDC(myHdc)
fails with "TypeError: argument number 1: object is not a PyCDC"

I need a DIB, I think, (or anything that can be used with pymedia).

I started working on a ctypes version:
CreateDIBitmap = windll.GDI32.CreateDIBitmap
etc., but that will take me some time, I think, and I'm not sure if 
it's the correct procedure anyway.

Thanks, more tries tomorrow.
Ray






At 05:02 PM 12/6/2006, Tim Roberts wrote:

Ray Schumacher wrote:
 > I've been mulling screen capture code. I tried PIL's
 > ImageGrab().grab() (with pymedia) but find PIL's method to be 
pretty
 > slow, ~4grabs per second max with no other processes.
 > pymedia is pretty quick once I hand it the data.
 >

How large is your screen?  A 1600x1200 true-color desktop is 8 
megabytes
worth of pixels, and it can take tens of milliseconds just to copy it
over the PCI bus to main memory.

 > There has to be another way to get a copy or buffer() of the 
screen
 > DC's data that is faster (I hope).
 >
 > I putsed around with win32gui
 > desktop = win32gui.GetDesktopWindow()
 > dt_l, dt_t, dt_r, dt_b = win32gui.GetWindowRect(desktop)
 > but couldn't see how to get at the data via the handle.
 >

You can use BitBlt to copy it to a DIB, but it's not going to be very
convenient to work with.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

_______________________________________________
Python-win32 mailing list
Python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32



More information about the Python-win32 mailing list