[Image-SIG] Monochrome image tostring length problems
Fredrik Lundh
fredrik at pythonware.com
Tue Nov 14 22:53:24 CET 2006
tom wrote:
> I'm having a real problem at the moment trying to figure out how to pass
> strings of 1bit image data between PIL and the g15daemon which supports
> the logitech g15 keyboards lcd. Basically, it's 160x143 in resolution.
> The g15 python bindings have two methods of note. The
> loader_10_ascii_format method loads a file which is formatted as
> 1001101110001 etc, and converts it in to a string of the form
> \x00\x01\x01\x00 etc.... this string has a len of 6880, which is the
> length it should be, being 160x43. If i try to do anything with a PIL
> created image initialised like
>
> i = Image.new('1', (160, 43))
>
> and then, with s being the string returned from the g15 ascii loader, do
> something like this
>
> i.fromstring(s)
>
> then you have a problem illustrated like so:
>
> len(i.tostring('raw', '1'))
> returns 860 (6880 / 8)
>
> len(i.tostring('raw', '1').encode('string-escape')
> returns 3440 half the number i need...
>
> I cannot send this string to the g15daemon.set_buffer method as it needs
> to be a string which is 6880 in length
try using
i = Image.new('L', (160, 43))
instead.
</F>
More information about the Image-SIG
mailing list