[ctypes-users] Saving a Device context (DC) into a picture file
Brought to you by:
theller
From: Michael C <mys...@gm...> - 2017-04-22 18:52:36
|
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) |