[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] using pil to covert rgb into grayscale
- To: pygame-users@xxxxxxxx
- Subject: [pygame] using pil to covert rgb into grayscale
- From: stas zytkiewicz <stas.zytkiewicz@xxxxxxxxx>
- Date: Thu, 29 Apr 2010 15:56:37 +0200
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Thu, 29 Apr 2010 09:56:52 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:reply-to:date :message-id:subject:from:to:content-type; bh=EOgZwNYbSWmiJQ2iF3yPoxkl3bmdnO+xqpwDNbXtOkA=; b=r51WjutLdIWh2PXPF2OfrHKBO+WHRgyhKBBQJm5AfFAeLrYJqhg+INRuEMrsk2rGY0 5lVirRzypaOWClBwIUFQXU+jVSQdCga5ZuYSPgcCZBgtgeEgt8DVB8b9wIfSLyaG091x D6ajM0MJwftfNEhRB0g5ImtqTariMjYSobqAY=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:date:message-id:subject:from:to:content-type; b=uFovqIJ6pzEMbaYIgxD2Wd3GHd9BIaP47BSMZjpYDYZt6pCWXH50Eo6m6BTbGDRZWX YGX+4KPDtx4ZXKbbo40MldRP4YJOzUJ5bI92SQRSlQvpGDpPDoSMg6lOXJoHQSQcke3N 4qdZBH3hJyXWDig3oDH8ElO1JnK3zvMl6JvBM=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
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