16bit RGB with Image module

Jason B me at mylife.com
Tue Mar 27 20:16:45 CEST 2007


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 





More information about the Python-list mailing list