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

Re: [pygame] image conversion in memory



On 08/13/2014 04:35 PM, diliup gabadamudalige wrote:
> This is the complete and correct code. Can anyone say what;s wrong?
> Thanks in advance.
> 
> 
> import pygame
> import StringIO
> 
> putimage = pygame.image.load("88keykbd.png")
> buff = StringIO.StringIO()
> buff.name <http://buff.name> = '88keykbd.png'
> 
> pygame.image.save(putimage, buff)
> 
> putimage = buff.getvalue()
> print "buff:", type(buff), "myimage:", type(putimage), "getimage:",
> type(putimage)
> 
> print len(putimage)
> with open('myscrambledimage.dat', 'w') as newfile:
>     newfile.write(putimage)
> 
> with open('myscrambledimage.dat', 'r') as newfile:
>     getimage= newfile.read()
> print len(getimage)

Open both files in binary mode, with 'wb' and 'rb' respectively.
Especially if you are on some funny operating system, like Windows.

Have you considered just putting all your images in a zip file, instead
of encoding them in strange ways?


-- 
The Sheep