16bit RGB with Image module
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
--
http://mail.python.org/mailman/listinfo/python-list
Re: 16bit RGB with Image module
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" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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
>
--
http://mail.python.org/mailman/listinfo/python-list
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: Pixel Array => Bitmap File
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 -- http://mail.python.org/mailman/listinfo/python-list
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" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 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 > -- http://mail.python.org/mailman/listinfo/python-list
sys.stdin and idle bug?
Greetings All, I apologize if this has been brought up before, but I'm having a small issue with the handling of sys.stdin in Idle. I'm using a routine to mimic the c library function getch(), to get a single character from the keyboard. The function works in the standard python shell, but in Idle I get an error when I try to reference sys.stdin.fileno(). Within the standard shell sys.stdin is a file object with a mode of 'r'. Looks like this in the interpreter: ', mode 'r' at 0xSome_address> However, in Idle the object is quite different: and typing sys.stdin.fileno() returns an AttributeError: fileno. Is this a bug in idle, or is this normal? If it's normal is there a work around for it? Thanks for any replies and references to more info on this issue. Sincerely, Jason Burke-- http://mail.python.org/mailman/listinfo/python-list
