-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow_window.py
More file actions
48 lines (36 loc) · 1.3 KB
/
Copy pathshow_window.py
File metadata and controls
48 lines (36 loc) · 1.3 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from tkinter import *
window = None
canvas = None
WIDTH, HEIGHT = 512, 512
window = Tk()
window.title("show window")
canvas = Canvas(window, width=WIDTH, height=HEIGHT)
def load_image(fname):
global WIDTH, HEIGHT
input_image = []
with open(fname, "rb") as file_path:
for i in range(0, HEIGHT):
temp_list = []
for j in range(0, WIDTH):
data_R = int.from_bytes(file_path.read(1), "little")
data_G = int.from_bytes(file_path.read(1), "little")
data_B = int.from_bytes(file_path.read(1), "little")
temp_tuple = (data_R, data_G, data_B)
temp_list.append(temp_tuple)
input_image.append(temp_list)
return input_image
def draw_image(image):
global WIDTH, HEIGHT
rgb_string = ""
for i in range(0, HEIGHT):
temp_string = ""
for j in range(0, WIDTH):
data = image[i][j]
temp_string += f"#{data[0]:02x}{data[1]:02x}{data[2]:02x} "
rgb_string += "{" + temp_string + "} "
paper.put(rgb_string)
paper = PhotoImage(width=WIDTH, height=HEIGHT)
canvas.create_image((WIDTH//2, HEIGHT//2), image=paper, state="normal")
draw_image(load_image("testfilefolder\data4.raw"))
canvas.pack()
window.mainloop()