16bit RGB with Image module

J

Jason B

Hi all,

I'm still new to all of this, but I'm trying to do something here that
*seems* like it should be pretty simple. All I want to do is take an array
of pixel data from a file (no header data or anything, just pixel data) in
RGB565 format and save it off to a bitmap file - or display it, in the case
below:

import sys, Image

if len(sys.argv) == 2:
print "\nReading: "+sys.argv[1]
image_file = open(sys.argv[1], "rb")
pixel_data = image_file.read()

im = Image.fromstring("RGB", (326, 325), pixel_data)
im.show()

When run, I get:

ValueError: not enough image data

Which I'm pretty sure is because it's expecting a 24bit image. Of course if
I tune down the width and height or change the format to B&W ("L") then it
*does* display an image, the B&W one even having recognizable features, just
not the right one. :(

I've read through the documentation a thousand times trying to understand
the raw decoder and plugins, etc. but I still can't figure this out...

Any help is greatly appreciated!

Thanks,
J
 
J

Jason B

Well I kept screwing around and funny thing, this works:

import sys, Image

if len(sys.argv) == 2:
print "\nReading: "+sys.argv[1]
image_file = open(sys.argv[1], "rb")
pixel_data = image_file.read()

im = Image.fromstring("RGB", (326, 325), pixel_data, "raw", "BGR;16")
im.show()

Although I have no idea *why* it works, other than the fact that I'm now
using the correct number of bits per pixel. :)

Anyone have thoughts on this?

Thanks!
J
 
W

Will McGugan

Jason said:
Well I kept screwing around and funny thing, this works:

import sys, Image

if len(sys.argv) == 2:
print "\nReading: "+sys.argv[1]
image_file = open(sys.argv[1], "rb")
pixel_data = image_file.read()

im = Image.fromstring("RGB", (326, 325), pixel_data, "raw", "BGR;16")
im.show()

Although I have no idea *why* it works, other than the fact that I'm now
using the correct number of bits per pixel. :)

Anyone have thoughts on this?

Well RGB will will use 24 bits per pixel, not 16, so the first error you
got makes sense. I guess using the raw decoder with "BGR;16" makes it
use 16 bit. Although, I couldn't find any reference in the docs!

I'm sure Fredrik Lundh could shed some light on this...

Will McGugan
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top