Re: [ctypes-users] Saving a Device context (DC) into a picture file
Brought to you by:
theller
From: Michael C <mys...@gm...> - 2017-04-22 19:15:45
|
Never mind, I found this https://books.google.ca/books?id=9MS9BQAAQBAJ&pg=PA116&lpg=PA116&dq=python+device+context+save&source=bl&ots=tYhl4K1K6J&sig=zgzJmOFeOIZL2C5eGrZ-Oa_QRB4&hl=en&sa=X&ved=0ahUKEwijjIvX37jTAhVQ42MKHVIFCHEQ6AEIOjAE#v=onepage&q=python%20device%20context%20save&f=false thanks all On Sat, Apr 22, 2017 at 11:52 AM, Michael C <mys...@gm...> wrote: > Quick Question: > I am using this code, and I have tried to find answers with google, and I > have read through MSDN. > > How do I save the DC into a png file or bmp? > > thanks! > > > import time > import ctypes > ##from ctypes import * > ## I don't like this. I like to import. > > time.sleep(2) > > # Set up the User32 and GDI32 > User32 = ctypes.WinDLL('User32', use_last_error=True) > GDI32 = ctypes.WinDLL('GDI32', use_last_error=True) > > # Set up Fx to be used. > GetForegroundWindow = User32.GetForegroundWindow > GetWindowDC = User32.GetWindowDC > GetPixel = GDI32.GetPixel > ReleaseDC = User32.ReleaseDC > > > # main code > foreground_window = GetForegroundWindow() > dc = GetWindowDC(foreground_window) > > # set timer to see how fast it runs. > t0 = time.clock() > > for i in range(50): > rgb = GetPixel(dc, 10, 10) > #print(rgb) > r = rgb & 0xff > g = (rgb >> 8) & 0xff > b = (rgb >> 16) & 0xff > ## print("RGB(%d, %d, %d)" % (r, g, b)) > > print(time.clock() - t0) > ReleaseDC(foreground_window, dc) > > |