[Tutor] if and things

elis aeris hunter92383 at gmail.com
Thu Jul 19 03:14:42 CEST 2007


#  pixel[]  is a list of tuples:   (r,g,b)
#  pixel[1030*(y-a) + x][0] = r
#  pixel[1030*(y-a) + x][1] = g
#  pixel[1030*(y-a) + x][2] = b

for a in range(0, 10):
    if    pixel[1030*(y-a) + x][1] > pixel[1030*(y-a) + x][0] and
pixel[1030*(y-a) + x][1] > pixel[1030*(y-a) + x][2]:
        box = box + 1

print box


i have never used double conditions before, is this correct?

I want box++ when  the g is both bigger than r and b.

















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[1][0]

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070719/2e63153c/attachment-0001.htm 


More information about the Tutor mailing list