[Image-SIG] PIL: Can't open saved BMP image
Sheila King
sheila at thinkspot.net
Mon Aug 4 12:06:12 EDT 2003
I am just trying out PIL since last night, and only doing the most basic of
stuff.
I had gotten down how to create a new image and draw lines and pixels and
save as a BMP image last night, and then I would be able to open them in
Ulead's PhotoImpact or other image viewing software if I so desired.
Well, today I ran a script and the first time it saved the image just fine
for me, but on repeated runs the script completes without error, but when I
try to open the saved image in anything (including PIL), I get an error
that it cannot open the image.
Here is the script that is creating the image (on Win32 Python 2.2.2 under
Windows 2000):
-------(begin creation script)----------------
import Image, ImageDraw
graph = Image.new("RGB", (660,350), "white")
drw = ImageDraw.Draw(graph)
drw.setink("black")
## draw axes
## horizontal axis
for y in range(300,305):
drw.line((50,y,650,y))
graph.show()
## vertical axis
for x in range(45,50):
drw.line((x,0,x,305))
graph.show()
graph.save(open("graphout2.bmp", "w"))
--------(end creation script)-----------------
BTW, the "show" commands work just fine and open up BMP images for me in
Ulead PhotoImpact.
However, the saved graphic, "graphout2.bmp" cannot be opened.
Here is a traceout from trying to open in PIL.
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> import Image
>>> im = Image.open("graphout2.bmp")
Traceback (most recent call last):
File "<pyshell#1>", line 1, in ?
im = Image.open("graphout2.bmp")
File "E:\PYTHON22\Lib\site-packages\PIL\Image.py", line 1556, in open
return factory(fp, filename)
File "E:\PYTHON22\Lib\site-packages\PIL\ImageFile.py", line 78, in
__init__
self._open()
File "E:\PYTHON22\Lib\site-packages\PIL\BmpImagePlugin.py", line 164, in
_open
self._bitmap(offset=offset)
File "E:\PYTHON22\Lib\site-packages\PIL\BmpImagePlugin.py", line 96, in
_bitmap
raise IOError("Unsupported BMP header type (%d)" % len(s))
IOError: Unsupported BMP header type (10240)
>>>
If I'm doing something stupid here, I'd certainly appreciate someone giving
me a kick in the head and setting me straight.
Thanks,
--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org
More information about the Image-SIG
mailing list