OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How can I read a binary file and turn the data into an image?

  • Thread starter Thread starter Hussien Hussien
  • Start date Start date
H

Hussien Hussien

Guest
Basically what I want to do is take a file, bring its binary data(decimal of course) into an list and then generate a grayscale bitmap image using PIL based on that list.

For example if the file is 5000 bytes (image size will be 100 x 50) and each byte is an integer between 0 and 255, I want to paint the first byte to the first pixel and go down the row until all bytes are exhausted.

The only thing I got so far is reading the file in:

Code:
f = open(file, 'rb')
text = f.read()
for s in text:
    print(s)

This outputs the bytes in decimal.

I'm looking for some direction on how to accomplish this. I've done a lot of searching, but it doesn't seem too many have tried doing what I want to do.

Any help would be greatly appreciated!
<p>Basically what I want to do is take a file, bring its binary data(decimal of course) into an list and then generate a grayscale bitmap image using PIL based on that list.</p>

<p>For example if the file is 5000 bytes (image size will be 100 x 50) and each byte is an integer between 0 and 255, I want to paint the first byte to the first pixel and go down the row until all bytes are exhausted.</p>

<p>The only thing I got so far is reading the file in:</p>

<pre><code>f = open(file, 'rb')
text = f.read()
for s in text:
print(s)
</code></pre>

<p>This outputs the bytes in decimal.</p>

<p>I'm looking for some direction on how to accomplish this. I've done a lot of searching, but it doesn't seem too many have tried doing what I want to do.</p>

<p>Any help would be greatly appreciated!</p>
 

Latest posts

Top