-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrawToImg.py
More file actions
34 lines (27 loc) · 708 Bytes
/
rawToImg.py
File metadata and controls
34 lines (27 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from PIL import Image, ImageDraw
f = open("binary_file.bin", mode="rb")
# Reading file data with read() method
data = f.read()
width = int.from_bytes(data[0:4], byteorder='big')
height = int.from_bytes(data[4:8], byteorder='big')
print(width, height)
image = Image.new("RGBA", (width, height))
draw = ImageDraw.Draw(image)
row = 0
column = 0
data = data[8:]
for i in range(0,len(data),4):
r = data[i+0]
g = data[i+1]
b = data[i+2]
a = data[i+3]
column += 1
if column == width:
column = 0
row += 1
if i+4 <= len(data):
if column < width and row < height:
image.putpixel((column, row), (r, g, b, a))
print(len(data))
image.show()
f.close()