'bitstream' is an array where each element contains 8 bits, i.e. etc. etc.

I want to print out this array to a file so it'll be recognised and can be opened as a jpeg.

I have tried the following:

output = open('outputfile.jpg', 'wb')
for i in range(len(bitstream)):

and this...

bitstreamtoprint = string.join(bitstream, "")

output = open('outputfile.jpg', 'wb')
for i in range(len(bitstreamtoprint)):

however neither of these work, they create the file but it won't open as a jpeg, no matter what application I try to open them in. I'm using Windows Vista, and have also tried opening the files in Ubuntu Linux and it does not work on that either - I get an error saying the file is corrupted or that it is not a jpeg.

Any help?

8 Years
Discussion Span
Last Post by vegaseat

Ok... but how exactly would I write that data to a file as a jpeg, or bitmap file? This is what is confusing me...


If you use a library like PIL or pygame, you can pass that data to the library and let it handle to compression and saving for you.

Just a thought.


I played around with PIL a while back and pretty much came to the conclusion that it needs a list of (r, g, b) tuples to work. You could potentially translate a color value to an (r, g, b) tuple.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.