Pixel Array => Bitmap File

Discussion in 'Python' started by Jason B, Feb 27, 2007.

  1. Jason B

    Jason B Guest

    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
    Jason B, Feb 27, 2007
    #1
    1. Advertising

  2. 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
    Roel Schroeven, Feb 27, 2007
    #2
    1. Advertising

  3. Jason B

    Jason B Guest

    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
    Jason B, Feb 27, 2007
    #3
  4. Jason B

    Jason B Guest

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

    Thanks again for your help!

    - J


    "Jason B" <> wrote in message
    news:mV1Fh.2439$...
    > 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
    >
    Jason B, Feb 27, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?cGJ1bQ==?=

    GDI+ - limits for pixel dimensions in a bitmap object

    =?Utf-8?B?cGJ1bQ==?=, Jun 18, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    355
    =?Utf-8?B?cGJ1bQ==?=
    Jun 18, 2004
  2. Gandalf

    Masked bitmap from bitmap

    Gandalf, Jan 29, 2004, in forum: Python
    Replies:
    0
    Views:
    577
    Gandalf
    Jan 29, 2004
  3. ajay_itbhu
    Replies:
    2
    Views:
    463
  4. xqggz
    Replies:
    1
    Views:
    417
    Victor Bazarov
    Jun 19, 2007
  5. André Wagner

    Fastest pixel by pixel operation

    André Wagner, Mar 17, 2008, in forum: Java
    Replies:
    12
    Views:
    1,037
    Larry A Barowski
    Mar 19, 2008
Loading...

Share This Page