Pixel Array => Bitmap File

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jason B

    #1

    Pixel Array => Bitmap File

    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


  • Roel Schroeven

    #2
    Re: Pixel Array => Bitmap File

    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.frombuffe r() or Image.fromstrin g() (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/pi...book/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

    Comment

    • Jason B

      #3
      Re: Pixel Array => Bitmap File

      Thanks, Roel...

      The Image.frombuffe r() 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


      Comment

      • Jason B

        #4
        Re: Pixel Array => Bitmap File

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

        Thanks again for your help!

        - J


        "Jason B" <me@mylife.comw rote in message
        news:mV1Fh.2439 $M65.1505@newss vr21.news.prodi gy.net...
        Thanks, Roel...
        >
        The Image.frombuffe r() 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
        >

        Comment

        Working...