[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] using pil to covert rgb into grayscale



Hello, I'm trying to convert a RGB image into a grayscaled image
using PIL but pygame keeps throwing this error:
"ValueError: Buffer length does not equal format and resolution size"

Why this code doesn't work, I have no idea :-(

('surf' is a pygame.Surface)

pilimg = Image.fromstring('RGBA', surf.get_size(),
pygame.image.tostring(surf, 'RGBA'))
pilimg = pilimg.convert('L')
pilimg.show()# it's grayscaled
surf_gr = pygame.image.fromstring(pilimg.tostring(), pilimg.size, 'RGBA')

OK, I know the last 'RGBA' probably isn't correct but 'P' isn't either
nor is one of the other
possible modes.

Can someone explain to me how to properly convert a RGB into grayscale, with
or without PIL.

Thanks,
Stas

-- 
Free-source educational programs for schools
http://www.schoolsplay.org  and http://wiki.laptop.org/go/Schoolsplay
http://gvr.sf.net and http://wiki.laptop.org/go/Guido_van_Robot