Upload I2I-Paint.py
Browse files- I2I-Paint.py +813 -812
I2I-Paint.py
CHANGED
@@ -1,812 +1,813 @@
|
|
1 |
-
import tkinter as tk
|
2 |
-
from tkinter import filedialog, messagebox, simpledialog
|
3 |
-
from tkinterdnd2 import DND_FILES, TkinterDnD
|
4 |
-
from PIL import Image, ImageDraw, ImageGrab, ImageTk
|
5 |
-
import win32clipboard
|
6 |
-
import win32con
|
7 |
-
import io
|
8 |
-
import os
|
9 |
-
import winsound
|
10 |
-
from datetime import datetime
|
11 |
-
from colorsys import hsv_to_rgb
|
12 |
-
import colorsys
|
13 |
-
import random
|
14 |
-
import ctypes
|
15 |
-
import time
|
16 |
-
user32 = ctypes.windll.user32
|
17 |
-
|
18 |
-
class ImageDrawer(TkinterDnD.Tk):
|
19 |
-
def __init__(self):
|
20 |
-
super().__init__()
|
21 |
-
#クイックセーブのデフォルト保存フォルダを自分で指定したい方は次の行を書き換えてください。
|
22 |
-
self.default_save_folder = os.path.dirname(os.path.abspath(__file__)) + "/saved_image"
|
23 |
-
#画面の描画間隔: 50FPS => 0.02, 100FPS => 0.01, 125FPS => 0.008
|
24 |
-
self.refresh_time = 0.01
|
25 |
-
#補間の点の数: 数値を上げると線が途切れにくくなります
|
26 |
-
self.points = 64
|
27 |
-
|
28 |
-
|
29 |
-
self.hwnd = ctypes.windll.kernel32.GetConsoleWindow()
|
30 |
-
if self.hwnd:
|
31 |
-
ctypes.windll.user32.ShowWindow(self.hwnd, 0)
|
32 |
-
print("ターミナルを最小化します。")
|
33 |
-
|
34 |
-
window_width = 950
|
35 |
-
window_height = 996
|
36 |
-
self.img_width = self.img_height = self.resize_width = self.resize_height = 1024
|
37 |
-
self.geometry(f"{window_width}x{window_height}+0+0")
|
38 |
-
self.display_title()
|
39 |
-
self.current_size = (window_width, window_height)
|
40 |
-
|
41 |
-
# キャンバスとスクロールバーを含むフレーム
|
42 |
-
self.canvas_frame = tk.Frame(self)
|
43 |
-
self.canvas_frame.grid(row=0, column=0, padx=(10, 0),sticky="nsew")
|
44 |
-
# キャンバス
|
45 |
-
self.canvas = tk.Canvas(self.canvas_frame, bg="gray50", highlightthickness=0, bd=0)
|
46 |
-
self.canvas.grid(row=0, column=0, sticky="nsew")
|
47 |
-
self.canvas.bind("<B1-Motion>", self.paint) # 左ドラッグで描画
|
48 |
-
self.canvas.bind("<Button-1>", self.paint)
|
49 |
-
self.canvas.bind("<Button-2>", self.toggle_eraser)
|
50 |
-
self.canvas.bind("<Button-3>", self.Eyedropper) # 右クリックでスポイト
|
51 |
-
# `canvas_frame` をウィンドウ全体に広げる
|
52 |
-
self.grid_rowconfigure(0, weight=1)
|
53 |
-
self.grid_columnconfigure(0, weight=1)
|
54 |
-
# `canvas_frame` 内の `canvas` も拡張
|
55 |
-
self.canvas_frame.grid_rowconfigure(0, weight=1)
|
56 |
-
self.canvas_frame.grid_columnconfigure(0, weight=1)
|
57 |
-
# スクロールバー (縦)
|
58 |
-
self.y_scrollbar = tk.Scrollbar(self.canvas_frame, orient=tk.VERTICAL, command=self.canvas.yview)
|
59 |
-
self.y_scrollbar.grid(row=0, column=1, sticky="ns") # 縦スクロールバーをキャンバスの右端に配置
|
60 |
-
# スクロールバー (横)
|
61 |
-
self.x_scrollbar = tk.Scrollbar(self, orient=tk.HORIZONTAL, command=self.canvas.xview)
|
62 |
-
self.x_scrollbar.grid(row=1, column=0, sticky="ew") # 横スクロールバーをキャンバス下部に配置
|
63 |
-
# スクロール設定
|
64 |
-
self.canvas.configure(xscrollcommand=self.x_scrollbar.set, yscrollcommand=self.y_scrollbar.set)
|
65 |
-
# DND 設定
|
66 |
-
self.drop_target_register(DND_FILES)
|
67 |
-
self.dnd_bind("<<Drop>>", self.on_drop)
|
68 |
-
# ボタンエリア
|
69 |
-
button_frame = tk.Frame(self, bg="gray66")
|
70 |
-
button_frame.grid(row=2, column=0, columnspan=2, sticky="ew")
|
71 |
-
# # ボタン
|
72 |
-
new_image = tk.Button(button_frame, text="新規", command=lambda: self.display_size_input_window())
|
73 |
-
new_image.pack(side=tk.LEFT, padx=5)
|
74 |
-
tk.Frame(button_frame).pack(side="left", expand=True)
|
75 |
-
tk.Button(button_frame, text="開く", command=self.open_image)
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
save_image.
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
self.
|
85 |
-
self.
|
86 |
-
self.
|
87 |
-
self.
|
88 |
-
#
|
89 |
-
self.
|
90 |
-
|
91 |
-
tk.
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
self.brush_canvas.
|
96 |
-
self.brush_canvas.
|
97 |
-
self.brush_canvas.bind("<Button-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
self.eraser_button.
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
white_canvas.
|
110 |
-
|
111 |
-
|
112 |
-
black_canvas.
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
self.grayscale_canvas.
|
118 |
-
self.grayscale_canvas.
|
119 |
-
|
120 |
-
self.
|
121 |
-
|
122 |
-
self.
|
123 |
-
|
124 |
-
self.palette_canvas.
|
125 |
-
self.palette_canvas.
|
126 |
-
self.palette_canvas.bind("<Button-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
self.nav_canvas.
|
132 |
-
self.nav_canvas.
|
133 |
-
self.nav_canvas.bind("<Button-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
layer_button.
|
143 |
-
|
144 |
-
|
145 |
-
clipboard_button.
|
146 |
-
clipboard_button.
|
147 |
-
|
148 |
-
|
149 |
-
self.bind("<
|
150 |
-
self.bind("<
|
151 |
-
self.
|
152 |
-
self.
|
153 |
-
self.
|
154 |
-
self.
|
155 |
-
self.
|
156 |
-
self.
|
157 |
-
self.
|
158 |
-
self.
|
159 |
-
self.
|
160 |
-
|
161 |
-
self.
|
162 |
-
self.
|
163 |
-
self.
|
164 |
-
self.
|
165 |
-
self.
|
166 |
-
self.
|
167 |
-
self.
|
168 |
-
self.
|
169 |
-
self.
|
170 |
-
self.
|
171 |
-
self.
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
self.
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
self.size_input_window.
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
rb.
|
205 |
-
|
206 |
-
|
207 |
-
rb.
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
self.
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
self.
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
self.
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
self.
|
259 |
-
self.
|
260 |
-
self.
|
261 |
-
self.
|
262 |
-
self.
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
self.
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
pixels[x, y]
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
self.
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
self.
|
305 |
-
self.
|
306 |
-
self.
|
307 |
-
self.
|
308 |
-
self.
|
309 |
-
self.
|
310 |
-
self.
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
self.
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
self.
|
374 |
-
self.canvas.
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
self.
|
409 |
-
self.
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
self.
|
414 |
-
self.
|
415 |
-
self.
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
self.
|
422 |
-
|
423 |
-
|
424 |
-
self.
|
425 |
-
self.
|
426 |
-
|
427 |
-
|
428 |
-
self.
|
429 |
-
self.
|
430 |
-
|
431 |
-
self.
|
432 |
-
self.
|
433 |
-
self.
|
434 |
-
self.
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
self.
|
449 |
-
self.canvas.
|
450 |
-
self.canvas.
|
451 |
-
self.
|
452 |
-
|
453 |
-
|
454 |
-
self.
|
455 |
-
self.canvas.
|
456 |
-
self.canvas.
|
457 |
-
self.
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
self.
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
self.
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
self.
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
draw_line
|
510 |
-
|
511 |
-
|
512 |
-
self.
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
self.
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
self.
|
545 |
-
self.
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
self.
|
550 |
-
self.
|
551 |
-
self.
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
self.
|
559 |
-
self.
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
self.
|
571 |
-
self.
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
self.
|
576 |
-
self.
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
self.
|
583 |
-
self.
|
584 |
-
self.
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
self.
|
589 |
-
self.
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
self.
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
self.
|
603 |
-
|
604 |
-
|
605 |
-
self.
|
606 |
-
|
607 |
-
self.
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
self.
|
612 |
-
self.
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
self.
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
self.
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
self.
|
651 |
-
self.
|
652 |
-
self.
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
self.
|
657 |
-
self.
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
self.
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
self.
|
693 |
-
self.
|
694 |
-
|
695 |
-
self.
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
self.
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
self.
|
723 |
-
self.
|
724 |
-
|
725 |
-
|
726 |
-
self.
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
win32clipboard.
|
761 |
-
win32clipboard.
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
bmp_data.
|
782 |
-
bmp_data.write(
|
783 |
-
bmp_data.write(
|
784 |
-
bmp_data.write(
|
785 |
-
bmp_data.write(
|
786 |
-
bmp_data.
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
self.background_image
|
793 |
-
self.
|
794 |
-
self.
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
self.
|
799 |
-
self.
|
800 |
-
self.
|
801 |
-
self.
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
app
|
|
|
|
1 |
+
import tkinter as tk
|
2 |
+
from tkinter import filedialog, messagebox, simpledialog
|
3 |
+
from tkinterdnd2 import DND_FILES, TkinterDnD
|
4 |
+
from PIL import Image, ImageDraw, ImageGrab, ImageTk
|
5 |
+
import win32clipboard
|
6 |
+
import win32con
|
7 |
+
import io
|
8 |
+
import os
|
9 |
+
import winsound
|
10 |
+
from datetime import datetime
|
11 |
+
from colorsys import hsv_to_rgb
|
12 |
+
import colorsys
|
13 |
+
import random
|
14 |
+
import ctypes
|
15 |
+
import time
|
16 |
+
user32 = ctypes.windll.user32
|
17 |
+
|
18 |
+
class ImageDrawer(TkinterDnD.Tk):
|
19 |
+
def __init__(self):
|
20 |
+
super().__init__()
|
21 |
+
#クイックセーブのデフォルト保存フォルダを自分で指定したい方は次の行を書き換えてください。
|
22 |
+
self.default_save_folder = os.path.dirname(os.path.abspath(__file__)) + "/saved_image"
|
23 |
+
#画面の描画間隔: 50FPS => 0.02, 100FPS => 0.01, 125FPS => 0.008
|
24 |
+
self.refresh_time = 0.01
|
25 |
+
#補間の点の数: 数値を上げると線が途切れにくくなります
|
26 |
+
self.points = 64
|
27 |
+
|
28 |
+
|
29 |
+
self.hwnd = ctypes.windll.kernel32.GetConsoleWindow()
|
30 |
+
if self.hwnd:
|
31 |
+
ctypes.windll.user32.ShowWindow(self.hwnd, 0)
|
32 |
+
print("ターミナルを最小化します。")
|
33 |
+
|
34 |
+
window_width = 950
|
35 |
+
window_height = 996
|
36 |
+
self.img_width = self.img_height = self.resize_width = self.resize_height = 1024
|
37 |
+
self.geometry(f"{window_width}x{window_height}+0+0")
|
38 |
+
self.display_title()
|
39 |
+
self.current_size = (window_width, window_height)
|
40 |
+
|
41 |
+
# キャンバスとスクロールバーを含むフレーム
|
42 |
+
self.canvas_frame = tk.Frame(self)
|
43 |
+
self.canvas_frame.grid(row=0, column=0, padx=(10, 0),sticky="nsew")
|
44 |
+
# キャンバス
|
45 |
+
self.canvas = tk.Canvas(self.canvas_frame, bg="gray50", highlightthickness=0, bd=0)
|
46 |
+
self.canvas.grid(row=0, column=0, sticky="nsew")
|
47 |
+
self.canvas.bind("<B1-Motion>", self.paint) # 左ドラッグで描画
|
48 |
+
self.canvas.bind("<Button-1>", self.paint)
|
49 |
+
self.canvas.bind("<Button-2>", self.toggle_eraser)
|
50 |
+
self.canvas.bind("<Button-3>", self.Eyedropper) # 右クリックでスポイト
|
51 |
+
# `canvas_frame` をウィンドウ全体に広げる
|
52 |
+
self.grid_rowconfigure(0, weight=1)
|
53 |
+
self.grid_columnconfigure(0, weight=1)
|
54 |
+
# `canvas_frame` 内の `canvas` も拡張
|
55 |
+
self.canvas_frame.grid_rowconfigure(0, weight=1)
|
56 |
+
self.canvas_frame.grid_columnconfigure(0, weight=1)
|
57 |
+
# スクロールバー (縦)
|
58 |
+
self.y_scrollbar = tk.Scrollbar(self.canvas_frame, orient=tk.VERTICAL, command=self.canvas.yview)
|
59 |
+
self.y_scrollbar.grid(row=0, column=1, sticky="ns") # 縦スクロールバーをキャンバスの右端に配置
|
60 |
+
# スクロールバー (横)
|
61 |
+
self.x_scrollbar = tk.Scrollbar(self, orient=tk.HORIZONTAL, command=self.canvas.xview)
|
62 |
+
self.x_scrollbar.grid(row=1, column=0, sticky="ew") # 横スクロールバーをキャンバス下部に配置
|
63 |
+
# スクロール設定
|
64 |
+
self.canvas.configure(xscrollcommand=self.x_scrollbar.set, yscrollcommand=self.y_scrollbar.set)
|
65 |
+
# DND 設定
|
66 |
+
self.drop_target_register(DND_FILES)
|
67 |
+
self.dnd_bind("<<Drop>>", self.on_drop)
|
68 |
+
# ボタンエリア
|
69 |
+
button_frame = tk.Frame(self, bg="gray66")
|
70 |
+
button_frame.grid(row=2, column=0, columnspan=2, sticky="ew")
|
71 |
+
# # ボタン
|
72 |
+
new_image = tk.Button(button_frame, text="新規", command=lambda: self.display_size_input_window())
|
73 |
+
new_image.pack(side=tk.LEFT, padx=5)
|
74 |
+
tk.Frame(button_frame).pack(side="left", expand=True)
|
75 |
+
open_button = tk.Button(button_frame, text="開く", command=self.open_image)
|
76 |
+
open_button.pack(side=tk.LEFT)
|
77 |
+
open_button.bind("<Button-3>", self.get_clipboard_image)
|
78 |
+
tk.Frame(button_frame).pack(side="left", expand=True)
|
79 |
+
save_image = tk.Button(button_frame, text="保存", command=lambda: self.save_image(None))
|
80 |
+
save_image.pack(side=tk.LEFT, padx=(5,0))
|
81 |
+
save_image.bind("<Button-3>", self.save_image)
|
82 |
+
tk.Frame(button_frame).pack(side="left", expand=True)
|
83 |
+
|
84 |
+
self.brush_size = 5
|
85 |
+
self.hue = 0
|
86 |
+
self.saturation = 0
|
87 |
+
self.brightness = 0
|
88 |
+
self.color = self.precolor = "#000000"
|
89 |
+
self.cursor = None
|
90 |
+
# 線の太さ表示
|
91 |
+
self.brush_size_label = tk.Label(button_frame, text=self.brush_size, font=("Arial Black", 20, "bold"), width=3, bg="gray66", justify="right", anchor="e")
|
92 |
+
self.brush_size_label.pack(side=tk.LEFT)
|
93 |
+
tk.Frame(button_frame).pack(side="left", expand=True)
|
94 |
+
|
95 |
+
self.brush_canvas = tk.Canvas(button_frame, bg="white", highlightthickness=0, bd=0, width=120, height=40)
|
96 |
+
self.brush_canvas.pack(side=tk.LEFT, pady=3)
|
97 |
+
self.brush_canvas.bind("<Button-1>", self.select_blush_size)
|
98 |
+
self.brush_canvas.bind("<B1-Motion>", self.select_blush_size)
|
99 |
+
self.brush_canvas.bind("<Button-3>", self.toggle_eraser)
|
100 |
+
tk.Frame(button_frame).pack(side="left", expand=True)
|
101 |
+
|
102 |
+
self.eraser_button = tk.Button(button_frame, text="消", command=lambda: self.toggle_eraser(), font=("メイリオ", 15, "bold"), bg="black", fg="white")
|
103 |
+
self.eraser_button.pack(side=tk.LEFT, padx=(0,10))
|
104 |
+
self.eraser_button.bind("<Button-3>", self.toggle_eraser)
|
105 |
+
tk.Frame(button_frame).pack(side="left", expand=True)
|
106 |
+
|
107 |
+
black_white_frame = tk.Frame(button_frame, bg="gray66")
|
108 |
+
black_white_frame.pack(side=tk.LEFT)
|
109 |
+
white_canvas = tk.Canvas(black_white_frame, highlightthickness=0, bd=0, width=20, height=20, bg="white")
|
110 |
+
white_canvas.grid(row=0, column=0, padx=5)
|
111 |
+
white_canvas.bind("<Button-1>", self.white)
|
112 |
+
black_canvas = tk.Canvas(black_white_frame, highlightthickness=0, bd=0, width=20, height=20, bg="black")
|
113 |
+
black_canvas.grid(row=1, column=0, padx=5)
|
114 |
+
black_canvas.bind("<Button-1>", self.black)
|
115 |
+
tk.Frame(button_frame).pack(side="left", expand=True)
|
116 |
+
|
117 |
+
self.grayscale_canvas = tk.Canvas(button_frame, highlightthickness=0, bg="black", bd=0, width=40, height=40)
|
118 |
+
self.grayscale_canvas.pack(side=tk.LEFT,pady=3)
|
119 |
+
self.grayscale_canvas.bind("<Button-1>", self.pick_grayscale)
|
120 |
+
self.grayscale_canvas.bind("<B1-Motion>", self.pick_grayscale)
|
121 |
+
tk.Frame(button_frame).pack(side="left", expand=True)
|
122 |
+
self.grayscale_canvas_init()
|
123 |
+
|
124 |
+
self.palette_canvas = tk.Canvas(button_frame, highlightthickness=0, bd=0, width=360, height=40)
|
125 |
+
self.palette_canvas.pack(side=tk.LEFT, padx=5, pady=3)
|
126 |
+
self.palette_canvas.bind("<Button-1>", self.pick_palette_color)
|
127 |
+
self.palette_canvas.bind("<B1-Motion>", self.pick_palette_color)
|
128 |
+
self.palette_canvas.bind("<Button-3>", self.pick_palette_color)
|
129 |
+
tk.Frame(button_frame).pack(side="left", expand=True)
|
130 |
+
|
131 |
+
self.nav_canvas = tk.Canvas(button_frame, bg="navy", highlightthickness=0, bd=0, width=40, height=40)
|
132 |
+
self.nav_canvas.pack(side=tk.LEFT, pady=3)
|
133 |
+
self.nav_canvas.bind("<Button-1>", self.on_drag)
|
134 |
+
self.nav_canvas.bind("<B1-Motion>", self.on_drag)
|
135 |
+
self.nav_canvas.bind("<Button-3>", self.toggle_resize_image)
|
136 |
+
tk.Frame(button_frame).pack(side="left", expand=True)
|
137 |
+
|
138 |
+
layer_frame = tk.Frame(button_frame, bg="gray66")
|
139 |
+
layer_frame.pack(side=tk.RIGHT, padx=5)
|
140 |
+
self.layer_label = tk.Label(layer_frame, text="両", fg="white", bg="blue")
|
141 |
+
self.layer_label.grid(row=0, column=0)
|
142 |
+
layer_button = tk.Button(layer_frame, command = self.rotate_layer, text="Layer")
|
143 |
+
layer_button.grid(row=0, column=1)
|
144 |
+
layer_button.bind("<Button-3>", self.unite_layer)
|
145 |
+
clipboard_button = tk.Button(layer_frame, text="Clipboard",command= lambda: self.copy_to_clipboard(None))
|
146 |
+
clipboard_button.grid(row=1, column=0, columnspan=2)
|
147 |
+
clipboard_button.bind("<Button-3>", self.copy_to_clipboard)
|
148 |
+
|
149 |
+
self.bind("<MouseWheel>", self.change_brush_size) # ホイールで太さ変更
|
150 |
+
self.bind("<ButtonRelease>", self.on_release)
|
151 |
+
self.bind("<Configure>", lambda event: self.play_window_resize_event(event))
|
152 |
+
self.protocol("WM_DELETE_WINDOW", self.on_close)
|
153 |
+
self.image_path = None
|
154 |
+
self.eraser_mode = False # 消しゴムモードの初期状態
|
155 |
+
self.click_off = True
|
156 |
+
self.layer_mode = 0
|
157 |
+
self.last_paint_time = 0 # 最後に描画した時間
|
158 |
+
self.last_x, self.last_y = 0, 0
|
159 |
+
self.cursor = None
|
160 |
+
self.sizes = [(640, 1536), (768, 1344), (832, 1216), (896, 1152), (1024, 1024), (1152, 896), (1216, 832), (1344, 768), (1536, 640)]
|
161 |
+
# self.adjust_x, self.adjust_y = 0, 0
|
162 |
+
self.display_brush_canvas()
|
163 |
+
self.draw_palette_canvas()
|
164 |
+
self.init_palette_line()
|
165 |
+
self.change_bgcolor_grayscale_canvas()
|
166 |
+
self.view_rect = self.nav_canvas.create_rectangle(0, 0, 10, 10, outline="yellow", width=2)
|
167 |
+
self.background_image = Image.new("RGBA", (self.img_width, self.img_height), "#ffffff")
|
168 |
+
self.drawn_image = Image.new("RGBA", (self.img_width, self.img_height), (0, 0, 0, 0))
|
169 |
+
self.update_idletasks()
|
170 |
+
self.resize_mode = True
|
171 |
+
self.display_image()
|
172 |
+
self.update_view_rect()
|
173 |
+
winsound.PlaySound("C:/Windows/Media/Alarm02.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
174 |
+
|
175 |
+
def display_title(self):
|
176 |
+
self.title(f"I2I Paint 【{self.img_width} x {self.img_height}】")
|
177 |
+
|
178 |
+
def on_release(self, event):
|
179 |
+
self.click_off = True
|
180 |
+
|
181 |
+
def on_close(self):
|
182 |
+
result = messagebox.askyesno("確認", "終了してウインドウを閉じますか?", parent=self)
|
183 |
+
if result:
|
184 |
+
self.destroy()
|
185 |
+
|
186 |
+
def play_window_resize_event(self, event):
|
187 |
+
if hasattr(self, 'resize_timer') and self.resize_timer:
|
188 |
+
self.after_cancel(self.resize_timer)
|
189 |
+
self.resize_timer = self.after(500, self.check_if_resized)
|
190 |
+
|
191 |
+
def check_if_resized(self):
|
192 |
+
new_size = (self.winfo_width(), self.winfo_height())
|
193 |
+
if new_size != self.current_size: # サイズが変わっている場合
|
194 |
+
self.current_size = new_size
|
195 |
+
self.display_image(False) # サイズが確定したときに一度だけ呼び出す
|
196 |
+
|
197 |
+
def display_size_input_window(self):
|
198 |
+
self.size_input_window = tk.Toplevel(self)
|
199 |
+
self.size_input_window.title("画像サイズ選択")
|
200 |
+
tk.Label(self.size_input_window, text="画像サイズを選択してください").pack()
|
201 |
+
size_var = tk.IntVar(value=4) # デフォルトを中央の 1024x1024 に設定
|
202 |
+
self.radio_buttons = []
|
203 |
+
for index, size in enumerate(self.sizes):
|
204 |
+
rb = tk.Radiobutton(self.size_input_window, text=f"{size[0]} x {size[1]}", variable=size_var, value=index)
|
205 |
+
rb.pack(anchor="w")
|
206 |
+
self.radio_buttons.append(rb)
|
207 |
+
rb = tk.Radiobutton(self.size_input_window, text="キーボードから入力", variable=size_var, value=9)
|
208 |
+
rb.pack(anchor="w")
|
209 |
+
self.radio_buttons.append(rb)
|
210 |
+
tk.Button(self.size_input_window, text="決定", command=lambda: self.new_image(size_var.get())).pack()
|
211 |
+
parent_width = self.winfo_width()
|
212 |
+
parent_height = self.winfo_height()
|
213 |
+
parent_x = self.winfo_x()
|
214 |
+
parent_y = self.winfo_y()
|
215 |
+
self.size_input_window.update_idletasks()
|
216 |
+
# 子ウインドウのサイズを設定
|
217 |
+
child_width = self.size_input_window.winfo_width()
|
218 |
+
child_height = self.size_input_window.winfo_height()
|
219 |
+
# 子ウインドウの位置を親ウインドウの中心に設定
|
220 |
+
child_x = parent_x + (parent_width // 2) - (child_width // 2)
|
221 |
+
child_y = parent_y + (parent_height // 2) - (child_height // 2)
|
222 |
+
self.size_input_window.geometry(f"{child_width}x{child_height}+{child_x}+{child_y}")
|
223 |
+
|
224 |
+
def new_image(self, selected_size):
|
225 |
+
if hasattr(self, 'size_input_window') and self.size_input_window:
|
226 |
+
self.size_input_window.destroy()
|
227 |
+
if selected_size ==9:
|
228 |
+
while True:
|
229 |
+
input_str = simpledialog.askstring("新規画像サイズ", "幅と高さをスペースで区切って入力してください/n例: 「800 600」 (最大値は4096)")
|
230 |
+
if not input_str:
|
231 |
+
return
|
232 |
+
try:
|
233 |
+
width, height = map(int, input_str.split())
|
234 |
+
if 4096 > width > 0 and 4096 > height > 0:
|
235 |
+
self.img_width = width
|
236 |
+
self.img_height = height
|
237 |
+
break
|
238 |
+
except ValueError:
|
239 |
+
pass # 数値以外が入力された場合はやり直し
|
240 |
+
else:
|
241 |
+
self.img_width = self.resize_width = self.sizes[selected_size][0]
|
242 |
+
self.img_height = self.resize_height = self.sizes[selected_size][1]
|
243 |
+
self.canvas.config(scrollregion=(0, 0, self.img_width, self.img_height))
|
244 |
+
result = messagebox.askyesnocancel("背景色", f"新規画像:{self.img_width}x{self.img_height}/n新規画像を現在の色���塗りつぶしますか?\n(「いいえ」=白背景)", parent=self)
|
245 |
+
if result is None:
|
246 |
+
return
|
247 |
+
elif result:
|
248 |
+
background_color = self.color
|
249 |
+
else:
|
250 |
+
background_color = "#ffffff"
|
251 |
+
# 新しい画像を作成(RGBAモードで、背景色は透明)
|
252 |
+
self.background_image = Image.new("RGBA", (self.img_width, self.img_height), background_color)
|
253 |
+
# 塗りつぶし処理
|
254 |
+
draw = ImageDraw.Draw(self.background_image)
|
255 |
+
# 現在の色で全体を塗りつぶす
|
256 |
+
draw.rectangle([0, 0, self.img_width, self.img_height], fill=background_color)
|
257 |
+
# 必要に応じて描画後の画像をキャンバスに再表示する処理を追加
|
258 |
+
self.drawn_image = Image.new("RGBA", (self.img_width, self.img_height), (255, 255, 255, 0))
|
259 |
+
self.layer_mode = 0
|
260 |
+
self.layer_label.config(text="両", bg="blue")
|
261 |
+
self.resize_mode = True
|
262 |
+
self.display_image()
|
263 |
+
self.display_title()
|
264 |
+
winsound.PlaySound("C:/Windows/Media/chord.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
265 |
+
self.on_drag(None)
|
266 |
+
result = messagebox.askyesno("ノイズ", f"新規画像:{self.img_width}x{self.img_height}/n背景画面にノイズを載せますか?", parent=self)
|
267 |
+
if result:
|
268 |
+
noise_level = simpledialog.askinteger("ノイズ濃度", "ノイズの濃さを入力してください。(%)", minvalue=0, maxvalue=100, initialvalue=20, parent=self)
|
269 |
+
if noise_level:
|
270 |
+
self.background_image = self.add_noise_to_image(self.background_image, noise_level)
|
271 |
+
self.display_image()
|
272 |
+
|
273 |
+
def add_noise_to_image(self, image, noise_level):
|
274 |
+
# 画像をRGBAモードで開く(透明度も考慮)
|
275 |
+
img = image.convert("RGBA")
|
276 |
+
pixels = img.load() # ピクセルデータを取得
|
277 |
+
width, height = img.size
|
278 |
+
for y in range(height):
|
279 |
+
for x in range(width):
|
280 |
+
# ノイズの強さに応じてピクセルのRGB値をランダムに変化させる
|
281 |
+
if random.random() < (noise_level / 100.0): # noise_level%の確率でノイズ
|
282 |
+
r = random.randint(0, 255) # ランダムな赤の値
|
283 |
+
g = random.randint(0, 255) # ランダムな緑の値
|
284 |
+
b = random.randint(0, 255) # ランダムな青の値
|
285 |
+
a = pixels[x, y][3] # 元の透明度(アルファ値)を保持
|
286 |
+
pixels[x, y] = (r, g, b, a) # ノイズを加えた新しい色を設定
|
287 |
+
return img
|
288 |
+
|
289 |
+
def on_drop(self, event):
|
290 |
+
"""ドラッグアンドドロップで画像を開く"""
|
291 |
+
self.image_path = event.data.strip("{}") # ファイルパス取得
|
292 |
+
self.load_image(self.image_path)
|
293 |
+
|
294 |
+
def open_image(self):
|
295 |
+
"""ダイアログから画像を開く"""
|
296 |
+
file_path = filedialog.askopenfilename(filetypes=[("Image Files", "*.png;*.jpg;*.webp;*.gif;*.bmp")])
|
297 |
+
if file_path:
|
298 |
+
self.load_image(file_path)
|
299 |
+
|
300 |
+
def load_image(self, file_path):
|
301 |
+
self.image_path = file_path
|
302 |
+
try:
|
303 |
+
"""画像を読み込んでキャンバスに表示"""
|
304 |
+
self.background_image = Image.open(file_path).convert("RGBA")
|
305 |
+
self.img_width, self.img_height = self.background_image.size
|
306 |
+
self.drawn_image = Image.new("RGBA", (self.img_width, self.img_height), (0, 0, 0, 0))
|
307 |
+
self.layer_mode = 0
|
308 |
+
self.layer_label.config(text="両", bg="blue")
|
309 |
+
self.resize_mode = True
|
310 |
+
self.display_image()
|
311 |
+
self.display_title()
|
312 |
+
winsound.PlaySound("C:/Windows/Media/chimes.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
313 |
+
self.on_drag(None)
|
314 |
+
except Exception as e:
|
315 |
+
print(f"ファイルの読み込みに失敗しました: {e}")
|
316 |
+
|
317 |
+
def save_image(self, event=None):
|
318 |
+
"""タイムスタンプ付きで画像をファイルに保存"""
|
319 |
+
image_to_save = self.original_image
|
320 |
+
if event: # `event` が渡された場合(ショートカット保存)
|
321 |
+
folder_path = self.default_save_folder
|
322 |
+
try:
|
323 |
+
if not os.path.exists(folder_path):
|
324 |
+
os.mkdir(folder_path)
|
325 |
+
# タイムスタンプ付きのファイル名を作成
|
326 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
327 |
+
file_name = f"image_{timestamp}"
|
328 |
+
# 重複回避処理(既存ファイルがある場合は "+" を追加)
|
329 |
+
file_path = os.path.join(folder_path, file_name + ".png").replace('\\', '/')
|
330 |
+
while os.path.exists(file_path):
|
331 |
+
file_name += "+"
|
332 |
+
file_path = os.path.join(folder_path, file_name + ".png").replace('\\', '/')
|
333 |
+
# 画像を保存
|
334 |
+
image_to_save.save(file_path, "PNG")
|
335 |
+
print(f"画像を保存しました: {file_path}")
|
336 |
+
messagebox.showinfo("確認", f"画像を保存しました:\n{file_path}", parent=self)
|
337 |
+
except Exception as e:
|
338 |
+
print(f"保存エラー: {e}\n{folder_path}")
|
339 |
+
else: # `event` がない場合(手動保存)
|
340 |
+
timestamp = time.strftime("%Y%m%d_%H%M%S")
|
341 |
+
file_path = filedialog.asksaveasfilename(
|
342 |
+
defaultextension=".png",
|
343 |
+
filetypes=[("PNG 画像", "*.png"), ("JPEG 画像", "*.jpg"), ("BMP 画像", "*.bmp"), ("すべてのファイル", "*.*")],
|
344 |
+
initialfile=f"image_{timestamp}" # ここでデフォルト名を設定
|
345 |
+
)
|
346 |
+
if not file_path: # キャンセルされた場合は処理を中断
|
347 |
+
return
|
348 |
+
# 画像を保存
|
349 |
+
try:
|
350 |
+
image_to_save.save(file_path)
|
351 |
+
messagebox.showinfo("確認", f"画像を保存しました:/n{file_path}", parent=self)
|
352 |
+
except Exception as e:
|
353 |
+
print(f"保存エラー: {e}\n{file_path}")
|
354 |
+
|
355 |
+
def toggle_resize_image(self, event=None):
|
356 |
+
self.resize_mode = not self.resize_mode
|
357 |
+
self.display_image()
|
358 |
+
|
359 |
+
def on_drag(self, event):
|
360 |
+
if self.resize_mode:
|
361 |
+
winsound.PlaySound("C:/Windows/Media/Windows Exclamation.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
362 |
+
return
|
363 |
+
""" `nav_canvas` 上で矩形をドラッグして `canvas` をスクロール """
|
364 |
+
scale_x = self.img_width / 39
|
365 |
+
scale_y = self.img_height / 39
|
366 |
+
# `nav_canvas` の範囲内に収める
|
367 |
+
if event:
|
368 |
+
x = min(max(event.x, 0), 39)
|
369 |
+
y = min(max(event.y, 0), 39)
|
370 |
+
else:
|
371 |
+
x = y = 0
|
372 |
+
scroll_x = (x * scale_x) / self.img_width
|
373 |
+
scroll_y = (y * scale_y) / self.img_height
|
374 |
+
self.canvas.xview_moveto(scroll_x)
|
375 |
+
self.canvas.yview_moveto(scroll_y)
|
376 |
+
# `view_rect` を更新
|
377 |
+
self.update_view_rect()
|
378 |
+
|
379 |
+
def update_view_rect(self):
|
380 |
+
self.canvas.update()
|
381 |
+
""" `canvas` の表示範囲を `nav_canvas` に反映する """
|
382 |
+
canvas_x1 = self.canvas.xview()[0] * self.img_width
|
383 |
+
canvas_y1 = self.canvas.yview()[0] * self.img_height
|
384 |
+
canvas_x2 = self.canvas.xview()[1] * self.img_width
|
385 |
+
canvas_y2 = self.canvas.yview()[1] * self.img_height
|
386 |
+
# 縮小率を計算
|
387 |
+
scale_x = 40 / self.img_width
|
388 |
+
scale_y = 40 / self.img_height
|
389 |
+
# nav_canvas 上の矩形の位置を計算
|
390 |
+
x1 = canvas_x1 * scale_x
|
391 |
+
y1 = canvas_y1 * scale_y
|
392 |
+
x2 = canvas_x2 * scale_x
|
393 |
+
y2 = canvas_y2 * scale_y
|
394 |
+
# nav_canvas 上のビュー範囲を更新
|
395 |
+
self.nav_canvas.coords(self.view_rect, x1, y1, x2, y2)
|
396 |
+
|
397 |
+
def rotate_layer(self):
|
398 |
+
self.layer_mode = (self.layer_mode + 1) % 3
|
399 |
+
layer_mode_name = ["両", "前", "後"]
|
400 |
+
layer_mode_color = ["blue2", "green4", "orange3"]
|
401 |
+
self.layer_label.config(text= layer_mode_name[self.layer_mode], bg=layer_mode_color[self.layer_mode])
|
402 |
+
# winsound.PlaySound("C:/Windows/Media/chord.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
403 |
+
self.display_image()
|
404 |
+
|
405 |
+
def unite_layer(self, event):
|
406 |
+
result = messagebox.askyesno("レイヤー統合", "二つのレイヤーと統合して後レイヤーにします。\nよろしいですか?", parent=self)
|
407 |
+
if result:
|
408 |
+
self.background_image = Image.alpha_composite(self.background_image, self.drawn_image)
|
409 |
+
self.drawn_image = Image.new("RGBA", (self.img_width, self.img_height), (0, 0, 0, 0))
|
410 |
+
self.display_image()
|
411 |
+
|
412 |
+
def calculate_basic_value(self):
|
413 |
+
self.canvas.update()
|
414 |
+
self.frm_width = self.canvas.winfo_width()
|
415 |
+
self.frm_height = self.canvas.winfo_height()
|
416 |
+
self.adjust_x = self.adjust_y = 0
|
417 |
+
if self.img_width <= self.frm_width:
|
418 |
+
self.adjust_x = int((self.frm_width - self.img_width) / 2)
|
419 |
+
if self.img_height <= self.frm_height:
|
420 |
+
self.adjust_y = int((self.frm_height - self.img_height) / 2)
|
421 |
+
self.img_aspect_ratio = self.img_width / max(self.img_height, 1)
|
422 |
+
self.frame_aspect_ratio = self.frm_width / max(self.frm_height, 1)
|
423 |
+
if self.img_aspect_ratio > self.frame_aspect_ratio:
|
424 |
+
self.resize_width = self.frm_width
|
425 |
+
self.resize_height = int(self.frm_width / self.img_aspect_ratio)
|
426 |
+
self.dx, self.dy = 0, (self.frm_height - self.resize_height) / 2
|
427 |
+
else:
|
428 |
+
self.resize_height = self.frm_height
|
429 |
+
self.resize_width = int(self.frm_height * self.img_aspect_ratio)
|
430 |
+
self.dx, self.dy = (self.frm_width - self.resize_width) / 2, 0
|
431 |
+
self.resize_width = max(self.resize_width, 1)
|
432 |
+
self.resize_height = max(self.resize_height, 1)
|
433 |
+
self.ratio = self.img_width / max(self.resize_width, 1)
|
434 |
+
self.xplot = self.frm_width // 2
|
435 |
+
self.yplot = self.frm_height // 2
|
436 |
+
|
437 |
+
def display_image(self, sound = True):
|
438 |
+
self.calculate_basic_value()
|
439 |
+
if self.layer_mode == 0:
|
440 |
+
self.original_image = Image.alpha_composite(self.background_image, self.drawn_image)
|
441 |
+
elif self.layer_mode == 1:
|
442 |
+
self.original_image =self.drawn_image
|
443 |
+
else:
|
444 |
+
self.original_image = self.background_image
|
445 |
+
self.canvas.delete("all")
|
446 |
+
if self.resize_mode:
|
447 |
+
resized_image = self.original_image.resize((self.resize_width, self.resize_height), Image.LANCZOS)
|
448 |
+
self.photo_image = ImageTk.PhotoImage(resized_image)
|
449 |
+
self.canvas.create_image(self.xplot, self.yplot, anchor=tk.CENTER, image=self.photo_image)
|
450 |
+
self.canvas.image = self.photo_image # GC対策
|
451 |
+
self.canvas.config(scrollregion=(0, 0, self.frm_width, self.frm_height))
|
452 |
+
self.nav_canvas.config(bg="yellow")
|
453 |
+
else:
|
454 |
+
self.photo_image = ImageTk.PhotoImage(self.original_image)
|
455 |
+
self.canvas.create_image(self.adjust_x, self.adjust_y, anchor=tk.NW, image=self.photo_image)
|
456 |
+
self.canvas.image = self.photo_image # GC対策
|
457 |
+
self.canvas.config(scrollregion=(0, 0, self.img_width, self.img_height))
|
458 |
+
self.nav_canvas.config(bg="navy")
|
459 |
+
self.on_drag(None)
|
460 |
+
if sound:
|
461 |
+
winsound.PlaySound("C:/Windows/Media/chord.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
462 |
+
|
463 |
+
def display_brush_canvas(self):
|
464 |
+
if self.saturation < 0.1 and self.brightness > 0.9:
|
465 |
+
outcolor = "black"
|
466 |
+
else:
|
467 |
+
outcolor = self.color
|
468 |
+
self.brush_canvas.delete("all") # 以前の画像をクリア
|
469 |
+
x1, y1 = (60 - self.brush_size), (20 - self.brush_size)
|
470 |
+
x2, y2 = (60 + self.brush_size), (20 + self.brush_size)
|
471 |
+
self.brush_canvas.create_oval(x1, y1, x2, y2, fill=self.color, outline=outcolor)
|
472 |
+
self.brush_size_label.config(fg=self.color)
|
473 |
+
|
474 |
+
def display_grayscale_cursor(self):
|
475 |
+
self.grayscale_canvas.delete(self.cursor)
|
476 |
+
true_hue = self.hue * 360 # 0.0~1.0 を 0~360 に変換
|
477 |
+
inverse_hue = int(true_hue + 180) % 360 # 逆の色相を求める
|
478 |
+
r, g, b = hsv_to_rgb(inverse_hue / 360, 1, 1)
|
479 |
+
fill_color = f"#{int(r*255):02x}{int(g*255):02x}{int(b*255):02x}"
|
480 |
+
self.cursor = self.grayscale_canvas.create_text(self.saturation * 39, 39 - (self.brightness) * 39, text="◎", fill=fill_color)
|
481 |
+
self.display_brush_canvas()
|
482 |
+
|
483 |
+
def grayscale_canvas_init(self):
|
484 |
+
""" HUEの背景とアルファグラデーションを適用 """
|
485 |
+
# RGBA画像を作成(背景は完全に透明)
|
486 |
+
white = Image.new("RGBA", (40, 40), (0, 0, 0, 0))
|
487 |
+
draw_white = ImageDraw.Draw(white)
|
488 |
+
# アルファ値のグラデーション(左: 透明 → 右: 不透明)
|
489 |
+
for x in range(40):
|
490 |
+
alpha = int((1 - (x / 39)) * 255) # 0 (透明) ~ 255 (不透明)
|
491 |
+
for y in range(40):
|
492 |
+
draw_white.point((x, y), fill=(255, 255, 255, alpha))
|
493 |
+
# 黒のアルファグラデーション(上: 透明 → 下: 不透明)
|
494 |
+
black = Image.new("RGBA", (40, 40), (0, 0, 0, 0))
|
495 |
+
draw_black = ImageDraw.Draw(black)
|
496 |
+
for y in range(40):
|
497 |
+
alpha = int(y / 39 * 255) # 0 (透明) ~ 255 (不透明)
|
498 |
+
for x in range(40):
|
499 |
+
draw_black.point((x, y), fill=(0, 0, 0, alpha))
|
500 |
+
# 画像の合成(Imageオブジェクトを使用)
|
501 |
+
self.filter_image = Image.alpha_composite(white, black)
|
502 |
+
self.filter_tk = ImageTk.PhotoImage(self.filter_image)
|
503 |
+
# Canvasに適用
|
504 |
+
self.grayscale_canvas.create_image(0, 0, anchor=tk.NW, image=self.filter_tk)
|
505 |
+
|
506 |
+
def init_palette_line(self):
|
507 |
+
""" パレット上のHUEのラインを初期化 """
|
508 |
+
white_line = Image.new("RGBA", (1, 40), (0, 0, 0, 0))
|
509 |
+
draw_line = ImageDraw.Draw(white_line)
|
510 |
+
draw_line.line((0, 0, 0, 39), fill=(0, 0, 0, 255), width=1)
|
511 |
+
line_tk = ImageTk.PhotoImage(white_line)
|
512 |
+
self.hue_line_img = line_tk # GC対策
|
513 |
+
self.hue_line = self.palette_canvas.create_image(0, 0, anchor=tk.NW, image=self.hue_line_img)
|
514 |
+
|
515 |
+
def change_bgcolor_grayscale_canvas(self):
|
516 |
+
""" 背景色をHUEで変更し、グラデーションと合成 """
|
517 |
+
r, g, b = hsv_to_rgb(self.hue, 1, 1) # HUEをRGBに変換
|
518 |
+
color = f"#{int(r*255):02x}{int(g*255):02x}{int(b*255):02x}"
|
519 |
+
self.grayscale_canvas.config(bg=color)
|
520 |
+
self.display_grayscale_cursor()
|
521 |
+
hue_x = int(self.hue * 359) # HUEを0-39の範囲でスケール変換
|
522 |
+
self.palette_canvas.coords(self.hue_line, hue_x, 0)
|
523 |
+
|
524 |
+
def draw_palette_canvas(self):
|
525 |
+
"""HSVの���相 (H) と彩度 (S) を変化させたグラデーションを描画"""
|
526 |
+
for x in range(360): # x = 0 から x = 358 まで
|
527 |
+
hue = x / 359 # 色相を 0.0 ~ 1.0 に正規化
|
528 |
+
for y in range(40):
|
529 |
+
if y < 20:
|
530 |
+
saturation = y / 19 # 彩度 (0.0 ~ 1.0)
|
531 |
+
brightness = 1
|
532 |
+
else:
|
533 |
+
saturation = 1
|
534 |
+
brightness = 1 - 0.8 * ((y-20) / 19) # 明度 (0.0 ~ 1.0)
|
535 |
+
r, g, b = hsv_to_rgb(hue, saturation, brightness) # 明度は常に1.0(最大)
|
536 |
+
color = f"#{int(r*255):02x}{int(g*255):02x}{int(b*255):02x}"
|
537 |
+
self.palette_canvas.create_rectangle(x, y, x, y, outline=color, fill=color)
|
538 |
+
|
539 |
+
def hsv_to_hex_color(self, hue, saturation, brightness):
|
540 |
+
r, g, b = hsv_to_rgb(hue, saturation, brightness) # 明度は常に1.0(最大)
|
541 |
+
self.color = f"#{int(r*255):02x}{int(g*255):02x}{int(b*255):02x}"
|
542 |
+
|
543 |
+
def black(self, event):
|
544 |
+
self.brightness = 0
|
545 |
+
self.hsv_to_hex_color(self.hue, self.saturation, self.brightness)
|
546 |
+
self.black_and_white()
|
547 |
+
|
548 |
+
def white(self, event):
|
549 |
+
self.saturation = 0
|
550 |
+
self.brightness = 1
|
551 |
+
self.hsv_to_hex_color(self.hue, self.saturation, self.brightness)
|
552 |
+
self.black_and_white()
|
553 |
+
|
554 |
+
def black_and_white(self):
|
555 |
+
winsound.PlaySound("C:/Windows/Media/chord.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
556 |
+
self.display_grayscale_cursor()
|
557 |
+
if self.eraser_mode:
|
558 |
+
self.eraser_mode = False
|
559 |
+
self.eraser_button.config(bg="black")
|
560 |
+
self.brush_canvas.config(bg="white")
|
561 |
+
|
562 |
+
def Eyedropper(self, event):
|
563 |
+
"""右クリックでスポイト (カーソル下の色を取得)"""
|
564 |
+
x, y = self.winfo_rootx() + event.x, self.winfo_rooty() + event.y
|
565 |
+
img = ImageGrab.grab(bbox=(x, y, x + 1, y + 1))
|
566 |
+
color_rgb = img.getpixel((0, 0))
|
567 |
+
# RGBを0-1の範囲に変換
|
568 |
+
r, g, b = [x / 255.0 for x in color_rgb]
|
569 |
+
# RGBをHSVに変換
|
570 |
+
self.hue, self.saturation, self.brightness = colorsys.rgb_to_hsv(r, g, b)
|
571 |
+
self.hsv_to_hex_color(self.hue, self.saturation, self.brightness)
|
572 |
+
self.change_bgcolor_grayscale_canvas()
|
573 |
+
winsound.PlaySound("C:/Windows/Media/chord.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
574 |
+
if self.eraser_mode:
|
575 |
+
self.eraser_mode = False
|
576 |
+
self.eraser_button.config(bg="black")
|
577 |
+
self.brush_canvas.config(bg="white")
|
578 |
+
|
579 |
+
def pick_grayscale(self, event):
|
580 |
+
"""クリックした位置の色を取得し、ラベルに表示"""
|
581 |
+
x, y = event.x, event.y
|
582 |
+
self.saturation = min(max(x / 39, 0), 1)
|
583 |
+
self.brightness = min(max(1 - (y / 39), 0), 1)
|
584 |
+
self.hsv_to_hex_color(self.hue, self.saturation, self.brightness)
|
585 |
+
self.display_grayscale_cursor()
|
586 |
+
winsound.PlaySound("C:/Windows/Media/Windows Information Bar.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
587 |
+
if self.eraser_mode:
|
588 |
+
self.eraser_mode = False
|
589 |
+
self.eraser_button.config(bg="black")
|
590 |
+
self.brush_canvas.config(bg="white")
|
591 |
+
|
592 |
+
def pick_palette_color(self, event):
|
593 |
+
"""クリックした位置の色を取得し、ラベルに表示"""
|
594 |
+
x, y = event.x, event.y
|
595 |
+
self.hue = min(max(x / 359, 0), 1) # 色相 (0.0 ~ 1.0)
|
596 |
+
if event.num == 1:
|
597 |
+
if y < 20:
|
598 |
+
self.saturation = min(max(y / 19, 0), 1) # 彩度 (0.0 ~ 1.0)
|
599 |
+
self.brightness = 1
|
600 |
+
else:
|
601 |
+
y -= 20
|
602 |
+
self.saturation = 1
|
603 |
+
self.brightness = min(max(1 - (0.8 * y / 19), 0), 1) # 明度 (0.0 ~ 1.0)
|
604 |
+
else:
|
605 |
+
self.saturation = 1.0
|
606 |
+
self.brightness = 1.0
|
607 |
+
self.hsv_to_hex_color(self.hue, self.saturation, self.brightness)
|
608 |
+
self.change_bgcolor_grayscale_canvas()
|
609 |
+
winsound.PlaySound("C:/Windows/Media/Windows Information Bar.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
610 |
+
if self.eraser_mode:
|
611 |
+
self.eraser_mode = False
|
612 |
+
self.eraser_button.config(bg="black")
|
613 |
+
self.brush_canvas.config(bg="white")
|
614 |
+
|
615 |
+
def adjust_color_brightness(self, event):
|
616 |
+
"""マウスホイールで self.color の明度 (V) を調整"""
|
617 |
+
if self.eraser_mode:
|
618 |
+
return
|
619 |
+
old_color = self.color
|
620 |
+
delta = 0.05 # 1回のスクロールで増減する値
|
621 |
+
if event.delta > 0:
|
622 |
+
self.brightness = min(self.brightness + delta, 1)
|
623 |
+
else:
|
624 |
+
self.brightness = max(self.brightness - delta, 0)
|
625 |
+
self.hsv_to_hex_color(self.hue, self.saturation, self.brightness)
|
626 |
+
if not self.color == old_color:
|
627 |
+
self.display_grayscale_cursor()
|
628 |
+
winsound.PlaySound("C:/Windows/Media/Windows Information Bar.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
629 |
+
|
630 |
+
def change_brush_size(self, event):
|
631 |
+
widget = self.winfo_containing(event.x_root, event.y_root)
|
632 |
+
if widget == self.canvas:
|
633 |
+
self.brush_size = max(1, self.brush_size + (1 if event.delta > 0 else -1))
|
634 |
+
self.brush_size_label.config(text=self.brush_size) # ラベル更新
|
635 |
+
winsound.PlaySound("C:/Windows/Media/Windows Information Bar.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
636 |
+
self.display_brush_canvas()
|
637 |
+
else:
|
638 |
+
self.adjust_color_brightness(event)
|
639 |
+
|
640 |
+
def select_blush_size(self, event):
|
641 |
+
self.brush_size = abs(event.x - 60)
|
642 |
+
self.brush_size_label.config(text=self.brush_size) # ラベル更新
|
643 |
+
winsound.PlaySound("C:/Windows/Media/Windows Information Bar.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
644 |
+
self.display_brush_canvas()
|
645 |
+
|
646 |
+
def toggle_eraser(self, event=None):
|
647 |
+
"""消しゴムモードの切り替え"""
|
648 |
+
self.eraser_mode = not self.eraser_mode
|
649 |
+
if self.eraser_mode:
|
650 |
+
self.precolor = self.color
|
651 |
+
self.color = "white"
|
652 |
+
self.eraser_button.config(bg="red")
|
653 |
+
self.brush_canvas.config(bg="black")
|
654 |
+
winsound.PlaySound("C:/Windows/Media/Windows Exclamation.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
655 |
+
else:
|
656 |
+
self.color = self.precolor
|
657 |
+
self.eraser_button.config( bg="black")
|
658 |
+
self.brush_canvas.config(bg="white")
|
659 |
+
winsound.PlaySound("C:/Windows/Media/chord.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
660 |
+
self.display_brush_canvas() # ブラシの表示を更新
|
661 |
+
|
662 |
+
def paint(self, event):
|
663 |
+
if self.resize_mode:
|
664 |
+
x = self.canvas.canvasx(event.x) - self.dx
|
665 |
+
y = self.canvas.canvasy(event.y) - self.dy
|
666 |
+
# 縮尺計算(リサイズ後の描画座標を元の画像サイズにマッピング)
|
667 |
+
x_original = int(x * self.ratio)
|
668 |
+
y_original = int(y * self.ratio)
|
669 |
+
# 描画範囲を計算
|
670 |
+
x1, y1 = x_original - self.brush_size, y_original - self.brush_size
|
671 |
+
x2, y2 = x_original + self.brush_size, y_original + self.brush_size
|
672 |
+
x1, y1, x2, y2 = map(int, [x1, y1, x2, y2])
|
673 |
+
current_time = time.time()
|
674 |
+
time_difference = current_time - self.last_paint_time
|
675 |
+
if not self.click_off:
|
676 |
+
delta_x, delta_y = x_original - self.last_x, y_original - self.last_y
|
677 |
+
for i in range(0, self.points):
|
678 |
+
xx = self.last_x + (delta_x * i / self.points)
|
679 |
+
yy = self.last_y + (delta_y * i / self.points)
|
680 |
+
x1, y1 = (xx - self.brush_size), (yy - self.brush_size)
|
681 |
+
x2, y2 = (xx + self.brush_size), (yy + self.brush_size)
|
682 |
+
self.draw_point(x1, y1, x2, y2,)
|
683 |
+
self.draw_point(x1, y1, x2, y2)
|
684 |
+
if time_difference > self.refresh_time:
|
685 |
+
if self.layer_mode == 0:
|
686 |
+
self.original_image = Image.alpha_composite(self.background_image, self.drawn_image)
|
687 |
+
elif self.layer_mode == 1:
|
688 |
+
self.original_image = self.drawn_image
|
689 |
+
else:
|
690 |
+
self.original_image = self.background_image
|
691 |
+
resized_image = self.original_image.resize((self.resize_width, self.resize_height), Image.LANCZOS)
|
692 |
+
self.photo_image = ImageTk.PhotoImage(resized_image)
|
693 |
+
self.canvas.create_image(self.xplot, self.yplot, anchor=tk.CENTER, image=self.photo_image)
|
694 |
+
self.last_paint_time = current_time
|
695 |
+
self.click_off = False
|
696 |
+
self.last_x, self.last_y = x_original, y_original
|
697 |
+
else:
|
698 |
+
"""描画処理 (スクロール対応)"""
|
699 |
+
x = self.canvas.canvasx(event.x) - self.adjust_x
|
700 |
+
y = self.canvas.canvasy(event.y) - self.adjust_y
|
701 |
+
x1, y1 = (x - self.brush_size), (y - self.brush_size)
|
702 |
+
x2, y2 = (x + self.brush_size), (y + self.brush_size)
|
703 |
+
x1, y1, x2, y2 = map(int, [x1, y1, x2, y2])
|
704 |
+
current_time = time.time()
|
705 |
+
time_difference = current_time - self.last_paint_time
|
706 |
+
if not self.click_off:
|
707 |
+
delta_x, delta_y = x - self.last_x, y - self.last_y
|
708 |
+
for i in range(0, self.points):
|
709 |
+
xx = self.last_x + (delta_x * i / self.points)
|
710 |
+
yy = self.last_y + (delta_y * i / self.points)
|
711 |
+
x1, y1 = (xx - self.brush_size), (yy - self.brush_size)
|
712 |
+
x2, y2 = (xx + self.brush_size), (yy + self.brush_size)
|
713 |
+
self.draw_point(x1, y1, x2, y2,)
|
714 |
+
self.draw_point(x1, y1, x2, y2)
|
715 |
+
if time_difference > self.refresh_time:
|
716 |
+
if self.layer_mode == 0:
|
717 |
+
self.original_image = Image.alpha_composite(self.background_image, self.drawn_image)
|
718 |
+
elif self.layer_mode == 1:
|
719 |
+
self.original_image = self.drawn_image
|
720 |
+
else:
|
721 |
+
self.original_image = self.background_image
|
722 |
+
self.photo_image = ImageTk.PhotoImage(self.original_image)
|
723 |
+
self.canvas.create_image(self.adjust_x, self.adjust_y, anchor=tk.NW, image=self.photo_image)
|
724 |
+
self.last_paint_time = current_time
|
725 |
+
# 座標と時間を記録
|
726 |
+
self.click_off = False
|
727 |
+
self.last_x, self.last_y = x, y
|
728 |
+
|
729 |
+
def draw_point(self, x1, y1, x2, y2):
|
730 |
+
if self.layer_mode == 2:
|
731 |
+
draw =ImageDraw.Draw(self.background_image)
|
732 |
+
else:
|
733 |
+
draw = ImageDraw.Draw(self.drawn_image)
|
734 |
+
if self.eraser_mode:
|
735 |
+
draw.ellipse([x1, y1, x2, y2], fill=(0, 0, 0, 0)) # 完全な透明色
|
736 |
+
else:
|
737 |
+
draw.ellipse([x1, y1, x2, y2], fill=self.color)
|
738 |
+
|
739 |
+
def copy_to_clipboard(self, event):
|
740 |
+
"""キャンバス上に描かれた画像をクリップボードにコピー"""
|
741 |
+
if event:
|
742 |
+
clipboard_image = self.drawn_image.copy()
|
743 |
+
pixels = clipboard_image.load()
|
744 |
+
# 画像サイズを取得
|
745 |
+
width, height = clipboard_image.size
|
746 |
+
# アルファ値をチェックして黒に変換
|
747 |
+
for y in range(height):
|
748 |
+
for x in range(width):
|
749 |
+
r, g, b, a = pixels[x, y]
|
750 |
+
if a > 0: # アルファ値が0ではない部分
|
751 |
+
pixels[x, y] = (255, 255, 255, a)
|
752 |
+
else:
|
753 |
+
pixels[x, y] = (0, 0, 0, a)
|
754 |
+
else:
|
755 |
+
clipboard_image = self.original_image
|
756 |
+
output = io.BytesIO()
|
757 |
+
clipboard_image.convert("RGB").save(output, format="BMP")
|
758 |
+
data = output.getvalue()[14:]
|
759 |
+
try:
|
760 |
+
win32clipboard.OpenClipboard()
|
761 |
+
win32clipboard.EmptyClipboard()
|
762 |
+
win32clipboard.SetClipboardData(win32con.CF_DIB, data)
|
763 |
+
winsound.PlaySound("C:/Windows/Media/chimes.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
764 |
+
except Exception as e:
|
765 |
+
print(f"画像のコピーに失敗: {e}")
|
766 |
+
finally:
|
767 |
+
win32clipboard.CloseClipboard()
|
768 |
+
|
769 |
+
def get_clipboard_image(self, event=None):
|
770 |
+
win32clipboard.OpenClipboard()
|
771 |
+
try:
|
772 |
+
if win32clipboard.IsClipboardFormatAvailable(win32clipboard.CF_DIB):
|
773 |
+
data = win32clipboard.GetClipboardData(win32clipboard.CF_DIB)
|
774 |
+
else:
|
775 |
+
print("クリップボードに画像がありません。")
|
776 |
+
return None
|
777 |
+
finally:
|
778 |
+
win32clipboard.CloseClipboard()
|
779 |
+
|
780 |
+
# BMP のヘッダーを適切に追加して PIL 画像に変換
|
781 |
+
bmp_data = io.BytesIO()
|
782 |
+
bmp_data.write(b'BM') # BMP シグネチャ
|
783 |
+
bmp_data.write((len(data) + 14).to_bytes(4, 'little')) # ファイルサイズ
|
784 |
+
bmp_data.write(b'\x00\x00\x00\x00') # 予約領域
|
785 |
+
bmp_data.write((14 + 40).to_bytes(4, 'little')) # ピクセルデータまでのオフセット
|
786 |
+
bmp_data.write(data) # DIB データ
|
787 |
+
bmp_data.seek(0) # 先頭に戻す
|
788 |
+
|
789 |
+
# PIL 画像として開く
|
790 |
+
image = Image.open(bmp_data)
|
791 |
+
|
792 |
+
# 取得した画像を `self.background_image` に設定
|
793 |
+
self.background_image = image.convert("RGBA") # ここで RGBA に変換
|
794 |
+
self.img_width, self.img_height = self.background_image.size
|
795 |
+
self.drawn_image = Image.new("RGBA", (self.img_width, self.img_height), (0, 0, 0, 0))
|
796 |
+
|
797 |
+
# UI の更新
|
798 |
+
self.layer_mode = 0
|
799 |
+
self.layer_label.config(text="両", bg="blue")
|
800 |
+
self.resize_mode = True
|
801 |
+
self.display_image()
|
802 |
+
self.display_title()
|
803 |
+
|
804 |
+
# 効果音を鳴らす
|
805 |
+
winsound.PlaySound("C:/Windows/Media/chimes.wav", winsound.SND_FILENAME | winsound.SND_ASYNC)
|
806 |
+
|
807 |
+
# イベント処理
|
808 |
+
self.on_drag(None)
|
809 |
+
|
810 |
+
|
811 |
+
if __name__ == "__main__":
|
812 |
+
app = ImageDrawer()
|
813 |
+
app.mainloop()
|