Problem in Bitmap format 
Author Message
 Problem in Bitmap format

On Fri, 25 Apr 1997 16:49:04 -0400, francois Ziade

Quote:

>Iam trying to simply display a bitmap on  a button widget.
>I'am on Wondows 95 and I use pbrush to create new bitmap files.
>I can't display any bitmap I create, but therefore was
>successful to display the built-in bitmaps which means my code
>is correct. There is then a problem with the format because I
>couldn't also open the built-in bitmap files with pbrush, with
>the error "format...."
>What software should I use then to create bitmaps that I could
>display with Tk8.0?

>Anyhelp is greatly appreciated.

>Francois


Francois,

I've run into the same thing (using Python/Tkinter).  It seems Tk
wants bitmaps in .xbm format.  The only way I've succeeded is to use
paint shop to create the monochrome bit map, and then I wrote a python
script to take this .bmp and output a .xbm, which I can then use as

you the idea, although I just did this, so its not been tested too
much.  It seems to work with NxN (where N is a multiple of 8) images,
it I ouput a 'flipped" image from photo shop:

import string
import Image
import Numeric

name = 'histogram'
im = Image.open('d:\\python\\bmps\\%s.bmp' % name)
out = open('d:\\python\\xbms\\%s.xbm' % name, 'w+')

a = Numeric.array(im.tostring(), Numeric.UnsignedInt8)
w = im.size[0]
h = im.size[1]
num = ((w+7)/8)*h  # this should be the number of elements
                                # we write out

out.write('#define %s_width %d\n' % (name, w))
out.write('#define %s_height %d\n' % (name, h))
out.write('static unsigned char %s_bits[] = {' % name)

nw = 0
last = len(a) - 8
for i in range(0, len(a), 8):
    v = 0
    for j in range(8):
        if a[i+j]: v = v + (1<<j)
    if nw == 0:
        out.write('\n  ')
    if i == last:
        out.write(' 0x%02x}\n' % v)
    else:
        out.write(' 0x%02x,' % v)
    nw = (nw + 1) % 12

out.close()



Wed, 13 Oct 1999 03:00:00 GMT  
 Problem in Bitmap format

Quote:
> I've run into the same thing (using Python/Tkinter).  It seems Tk
> wants bitmaps in .xbm format.  The only way I've succeeded is to use
> paint shop to create the monochrome bit map, and then I wrote a python
> script to take this .bmp and output a .xbm, which I can then use as

> name = 'histogram'
> im = Image.open('d:\\python\\bmps\\%s.bmp' % name)
> out = open('d:\\python\\xbms\\%s.xbm' % name, 'w+')

Hmm.  PIL 0.2b4 directly supports XBM files back from release 0.2b1,
including a "tobitmap" method that returns the image as a string (this
is mentioned in the release notes, at least).  So

Image.open(bmpfile).save(xbmfile)

should work as well.  Note that by using the ImageTk.BitmapImage class
instead of the one in Tkinter, you don't need to convert the files at
all.

        bitmap = ImageTk.Bitmap(Image.open(bmpfile))
        w = Button(image=bitmap, command=...)

Cheers  /F (http://hem1.passagen.se/eff)



Sat, 16 Oct 1999 03:00:00 GMT  
 Problem in Bitmap format

On Tue, 29 Apr 1997 10:21:24 GMT, Fredrik Lundh

Quote:

>Hmm.  PIL 0.2b4 directly supports XBM files back from release 0.2b1,
>including a "tobitmap" method that returns the image as a string (this
>is mentioned in the release notes, at least).  So

>Image.open(bmpfile).save(xbmfile)

>should work as well.  Note that by using the ImageTk.BitmapImage class
>instead of the one in Tkinter, you don't need to convert the files at
>all.

>    bitmap = ImageTk.Bitmap(Image.open(bmpfile))
>    w = Button(image=bitmap, command=...)

Thanks.  You know I just ran into the tobitmap function 10 minutes
after I posted that message... read the source Luke... and felt
rather idiotic.

but when I try in my code:

bmap=ImageTk.BitmapImage(Image.open('d:/python/bmps/histogram.bmp'))

   self.toolBar.histogram = Tix.Button(self.toolBar,

bitmap=bmap,

command=self.histogram)
I get:

TclError: bitmap "9974928" not defined
from the bitmap=bmap option.

(win95, Pil .2b4, TckTk 8.0a2, Tix 1.12)

Cheers!

Roger



Sat, 16 Oct 1999 03:00:00 GMT  
 Problem in Bitmap format

Quote:
> bmap=ImageTk.BitmapImage(Image.open('d:/python/bmps/histogram.bmp'))

>    self.toolBar.histogram = Tix.Button(self.toolBar,

> bitmap=bmap,

  ^^^^^^ change this to "image"

Quote:

> command=self.histogram)

Using image= instead of bitmap= should do the trick.

Cheers  /F (http://hem1.passagen.se/eff)



Sat, 16 Oct 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Problem in Bitmap format

2. Converting Windows Bitmap to X bitmap format so that Tk can display it

3. How to Convert X Bitmap Format to Windows Bitmap Format?

4. Bitmap header format + PTR operator

5. Bitmap header format

6. The bitmap-format

7. Bitmap for icon != bitmap for button?

8. coloured bitmap with the option -bitmap ?

9. Bitmap related problem...

10. colour bitmap with mask problem

11. Bitmap problems in MSWLogo

 

 
Powered by phpBB® Forum Software