16bit RGB with Image module
Jason B
me at mylife.com
Tue Mar 27 14:23:05 EDT 2007
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
"Jason B" <me at mylife.com> wrote in message
news:hcdOh.9548$JZ3.7651 at newssvr13.news.prodigy.net...
> 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