pygame on win32, image.fromstring()

tlviewer tlviewerSHRUB at yahooCHENEY.com
Sat May 14 13:38:23 EDT 2005


"Greg Krohn" <greg at invalid.invalid> wrote in message
news:AYhhe.379$X92.275 at newsread2.news.pas.earthlink.net...
> tlviewer wrote:
> > hello,
>
> hi
>
> > fp = open( "e:/batch/python/aceclub.bmp", "wt")
>
> wt? Should this be wb?
>
> > # gives: ValueError: String length does not equal format and resolution
size
> > img = gm.image.fromstring(str,(71,96),"P")
>
> The pygame docs say "P" is for 8bit pallete indices. When I look at the
> properties of aceclub.bmp, Windows says it's Bit Depth is 4. I'm not sure
if
> they're talking about the same thing, though. If so, you could probably
use PIL
> to convert the depth.

Yes, that was the trouble. Based on your suggestion, I now massage the
image string with PIL, then fromstring() works!

obj =Image.open(StringIO.StringIO(str))

#obj.convert( mode='P')
# conversion is implicit, mode is 'P' already
img = gm.image.fromstring(obj.tostring(),(71,96),"P")

Next I'm going to load all 53 card resources into a list (array) of strings,
then
write it out, pickled. That should smooth out loading the game when I use
4-6 decks (Blackjack-21).

thanks for getting to my post so quickly,
tlviewer
--





More information about the Python-list mailing list