Most efficient way to get pixelcolors of an image?

defn noob circularfunc at yahoo.se
Wed Jul 2 12:34:16 EDT 2008


i want to process a large number of images and store their respective
pixels in a matrix.

what is the mostt efficient way of opening and checking them?
i doubt pygame is made for this purpose :)

i guess i could also use tkinter?


and why cant i print out matrix after getting the pixels? do i have to
deinit() pygame somehow?

import pygame
import sys
import os

print os.path.exists('C:/users/saftarn/desktop/images/bloba.bmp')

pygame.init()
screen = pygame.display.set_mode((800, 600))

image = pygame.image.load('C:/users/saftarn/desktop/images/bloba.bmp')
imrect = image.get_rect()
imrect = imrect.move(200, 200)

matrix = []

while 1:
    pygame.display.flip()
    screen.fill((255,255,255))
    screen.blit(image, imrect)
    pygame.event.wait()
    event = pygame.event.wait()

    for x in range(1, 301):
        for y in range(1, 301):
            matrix.append(screen.get_at((x, y)))

    #print matrix
    if event.type == pygame.QUIT:
        #print matrix
        sys.exit()



More information about the Python-list mailing list