[Tutor] Reading a "Raw "Image File

Emile van Sebille emile at fenx.com
Sun Apr 12 22:46:12 CEST 2009

Wayne Watson wrote:
> I can read a raw of 640x480 bytes with:
>    raw_file=open('sent_internal.raw')


>    raw_image=raw_file.read()
> It likely contains a lot of 0 values, black=0. The result above is a
> string of 242 characters. I'm guessing the 0's were ignored, and only >0
> values were kept. If so, how do I get all 307200 bytes into a read?
> Whoops ... Ah, I missed 'rb'; however, I want to continue.


> I found the minimum value among the first 242 items to be 31 without the
> 'rb'. 

the first 32 characters in ascii are control characters

> Among the 307200, I found it to be 150, which I believe is
> correct. That is, there are pixels in the image that are pretty bright.
> So what weirdness took place w/o the 'rb'? Why no 150?

not sure what this means...

> One more question, when I tried (no 'wb') 

assuming you mean 'rb' above

> read(size=307200), 
> why di read
> balk at size, syntactically.

read terminates upon first end on line character encountered



More information about the Tutor mailing list