Pixel Array => Bitmap File

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Tue Feb 27 16:56:43 EST 2007


Jason B schreef:
> Hi all,
> 
> I'm somewhat new to Python and I'm trying to figure out the best way to 
> accomplish the following:
> 
> From an array of pixel data in an XML file (given the format, width and 
> height of the image as attributes) I must read in the data and save it off 
> as a bmp file.
> 
> I've gotten the PIL and Win32 packages and it seems that using 
> functionallity from each I should be able to do this, but I haven't yet 
> figured out how.
> 
> Scouring the internet for a tutorial hasn't netted me anything so far, so I 
> was hoping someone here could point me in the right direction...

- read your pixels from the XML file and assemble them in the correct 
format in a buffer
- use Image.frombuffer() or Image.fromstring() (from PIL) to create an 
image from that data
- use Image.save() (also from PIL) to save it as a bmp.

Have a look at http://www.pythonware.com/library/pil/handbook/image.htm 
for the details on those methods.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven



More information about the Python-list mailing list