import time import ImageGrab # Part of PIL from ctypes import *
# Load up the Win32 APIs we need to use. class RECT(Structure): _fields_ = [ ('left', c_ulong), ('top', c_ulong), ('right', c_ulong), ('bottom', c_ulong) ] # time.sleep(2) GetForegroundWindow = windll.user32.GetForegroundWindow GetWindowRect = windll.user32.GetWindowRect # Sleep for 2 seconds - click the window you want to grab. #time.sleep(2) # Grab the foreground window's screen rectangle. rect = RECT() foreground_window = GetForegroundWindow() GetWindowRect(foreground_window, byref(rect)) image = ImageGrab.grab((rect.left, rect.top, rect.right, rect.bottom)) # Save the screenshot as a BMP. time.sleep(2) image.save("c:\python_codes\screenshot.bmp") # Get the pixel 10 pixels along the top of the foreground window - this # will be a piece of the window border. # print time.time() start = time.time() pixels = image.getdata() for x in xrange(0, 500): for y in xrange(0, 500): rgb = pixels[500 * x + y] # print pixels[500 * 2 + 400] print ( time.time() - start ) # PIL returns colours as RGB values packed into a triple: #print "RGB(%d, %d, %d)" % (rgb[0], rgb[1], rgb[2]) # This prints RGB(0, 74, 216) on my XP machine getdata() returns a flattened list, [n] but i am not sure how to access it. when I want to get rgb from a window of 100,200, get data starts from 0 (0~99, 0~199) the point of x,y = 2, 1 do I put in pixel[100] ? it's actually not the case @_@ what should I put in ?
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor