[Image-SIG] BitmapImage instanciation of an xbm
Nathan Johnson
njohnson at natural-selection.com
Mon Nov 17 20:28:32 EST 2003
When I try to open an xbm image either from file or embedded in
python code(as shown below) the PIL says it can't identify the
image file. It seems like the BitmapImage class should be able
to recognize the standard xbm format. The reason I'm using the
PIL to open the xbm is because I need to resize the image. If
anybody knows a better way of opening a .xbm file and being able
to resize it, I'm open to suggestions.
I'm running Python 2.3.2 with PIL 1.1.4 on Linux
Thanks,
Nate
---------------------------------------------------------------
#!/usr/bin/env python
from ImageTk import BitmapImage
BITMAP = """
#define basic_width 32
#define basic_height 32
static char basic_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x80, 0xff, 0xff, 0x01, 0x40, 0x00, 0x00, 0x02,
0x20, 0x00, 0x00, 0x04, 0x20, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08,
0x20, 0x00, 0x00, 0x04,
0x20, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x02,
0x80, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
"""
icon = BitmapImage(data=BITMAP)
---------------------------------------------------------------
Traceback (most recent call last):
File "exp.py", line 28, in ?
icon = BitmapImage(data=BITMAP)
File "/usr/lib/python2.3/site-packages/PIL/ImageTk.py", line 219, in
__init__
image = Image.open(StringIO(kw["data"]))
File "/usr/lib/python2.3/site-packages/PIL/Image.py", line 1571, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file
Exception exceptions.AttributeError: "BitmapImage instance has no attribute
'_BitmapImage__photo'"
in <bound method BitmapImage.__del__ of <ImageTk.BitmapImage instance at
0x400bff4c>> ignored
More information about the Image-SIG
mailing list