Pixel Array => Bitmap File

J

Jason B

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...

Thanks!
J
 
R

Roel Schroeven

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.
 
J

Jason B

Thanks, Roel...

The Image.frombuffer() method looks promising, but the "mode" parameter
seems a bit too limited for my needs. I must be able to specify not only
the order of the bits (RGB in any order) but also whether the format is 565,
555, etc.

Maybe I need to work outside the bounds of PIL?

- J
 
J

Jason B

My mistake, I see the section now about "Writing Your Own File Decoder..."

Thanks again for your help!

- J
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top