uccjshrimpton

Open Bitmap Image Procedure

Jul 18th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter.filedialog import askopenfile
  3.  
  4. def get_file():
  5.     image_file = askopenfile(parent=main_window, title='Select a Bitmap File')
  6.     image_file = open(image_file.name, "rb")
  7.     all_bytes = list(image_file.read())
  8.  
  9.     for index, byte in enumerate(all_bytes):
  10.         all_bytes[index] = str(hex(byte)[2:])
  11.  
  12.     # [x:x:-1] = start, end, steps
  13.     offset = int(str("".join(all_bytes[13:9:-1])), 16)
  14.     width = int(str("".join(all_bytes[21:17:-1])), 16)
  15.     height = int(str("".join(all_bytes[25:21:-1])), 16)
  16.     depth = int(str("".join(all_bytes[29:27:-1])), 16)
  17.  
  18.     print("Offset:", offset)
  19.     print("Width:", width)
  20.     print("Height:", height)
  21.     print("Depth:", depth)
  22.  
  23.     # pixel data stored from bottom right to top left
  24.     all_pixel_data = all_bytes[offset:]
  25.  
  26. main_window = Tk()
  27. main_window.title("Bitmap Interpreter")
  28.  
  29. button_open = Button(main_window, text="Open Bitmap", command=get_file)
  30. button_open.pack()
  31.  
  32. main_window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment