fix export and redraw
This commit is contained in:
+10
-20
@@ -58,13 +58,12 @@ class Bitmap:
|
|||||||
elif len(data) > size:
|
elif len(data) > size:
|
||||||
data = data[:size]
|
data = data[:size]
|
||||||
line_padding = (width * 3) % 4
|
line_padding = (width * 3) % 4
|
||||||
if line_padding == 0:
|
|
||||||
return data
|
|
||||||
output_data = bytes()
|
output_data = bytes()
|
||||||
for y in range(height):
|
for y in range(height):
|
||||||
start = y * 3 * width
|
start = (height - y - 1) * 3 * width
|
||||||
output_data += data[start : start + width]
|
output_data += data[start : start + width * 3]
|
||||||
output_data += bytes([0]) * line_padding
|
if line_padding > 0:
|
||||||
|
output_data += bytes([0]) * (4 - line_padding)
|
||||||
return output_data
|
return output_data
|
||||||
|
|
||||||
|
|
||||||
@@ -117,6 +116,10 @@ class Image:
|
|||||||
output += bytes([255, 255, 255])
|
output += bytes([255, 255, 255])
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
def export_bmp(self, path: str) -> None:
|
||||||
|
with open(path, mode="wb") as f:
|
||||||
|
f.write(Bitmap.get_bmp_data(self.width, self.get_color_bytes()))
|
||||||
|
|
||||||
|
|
||||||
class File:
|
class File:
|
||||||
FILE_TYPES = [("Header File", "*.h"), ("All Files", "*.*")]
|
FILE_TYPES = [("Header File", "*.h"), ("All Files", "*.*")]
|
||||||
@@ -334,14 +337,7 @@ class App(ttk.Frame):
|
|||||||
height=(image.height * DRAW_SCALE),
|
height=(image.height * DRAW_SCALE),
|
||||||
background="white",
|
background="white",
|
||||||
)
|
)
|
||||||
self.canvas.create_rectangle(
|
self.canvas.delete("all")
|
||||||
0,
|
|
||||||
0,
|
|
||||||
(image.width * DRAW_SCALE),
|
|
||||||
(image.height * DRAW_SCALE),
|
|
||||||
fill="white",
|
|
||||||
outline="",
|
|
||||||
)
|
|
||||||
for x in range(image.width):
|
for x in range(image.width):
|
||||||
for y in range(image.height):
|
for y in range(image.height):
|
||||||
if image.get_pixel(x, y):
|
if image.get_pixel(x, y):
|
||||||
@@ -431,13 +427,7 @@ class App(ttk.Frame):
|
|||||||
initialfile=f"{self.current_image.name}.bmp",
|
initialfile=f"{self.current_image.name}.bmp",
|
||||||
)
|
)
|
||||||
if path is not None:
|
if path is not None:
|
||||||
with open(path, mode="wb") as f:
|
self.current_image.export_bmp(path)
|
||||||
f.write(
|
|
||||||
Bitmap.get_bmp_data(
|
|
||||||
self.current_image.width, self.current_image.get_color_bytes()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = App(Tk())
|
app = App(Tk())
|
||||||
|
|||||||
Reference in New Issue
Block a user