Raw images

Fredrik Lundh fredrik at pythonware.com
Wed Dec 21 02:05:10 EST 2005


"Tuvas" wrote:

> 1. Read string
> 2. Form an array by combining 2 chars together.
> 3. Divide by 256 so as to have a 8 bit number, which PIL likes alot
> better than a 16 bit number. The string is called data.
> 4. Use im = Image.fromstring('L', (xsize, ysize), data) to create image

PIL can do this conversion for you (by specifying a "raw mode" to
fromstring).  I'll post an example later.

>        image=ImageTk.BitmapImage(im)
>        pic=canvas.create_image(1,1,anchor="nw",image=image,tag="pic")
>        canvas.addtag_withtag("pic",pic)
>
> There seems to be a problem with the last line, but no picture is
> displayed without it. That isn't related to the problem I'm having, but
> I also need to fix it. The problem is it won't display the image, it
> seems to display nothing. Any ideas as to why?

if you have a grayscale image, you should use PhotoImage, not BitmapImage.

as for the disappearing image, see the note at the bottom of this page:

    http://www.effbot.org/tkinterbook/photoimage.htm

</F> 






More information about the Python-list mailing list