色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

python 實(shí)現(xiàn)圖片裁剪小工具

瀏覽:4日期:2022-06-28 14:30:28

完整項(xiàng)目地址下載:https://github.com/rainbow-tan/rainbow/tree/master/%E8%A3%81%E5%89%AA%E5%9B%BE%E7%89%87

實(shí)現(xiàn):tkinter 畫布上顯示圖片,按下鼠標(biāo)左鍵并且移動(dòng),實(shí)現(xiàn)截圖

# -*- encoding=utf-8 -*-import osimport tkinter as tkfrom PIL import Imagefrom PIL import ImageTkleft_mouse_down_x = 0left_mouse_down_y = 0left_mouse_up_x = 0left_mouse_up_y = 0sole_rectangle = Nonedef left_mouse_down(event): # print(’鼠標(biāo)左鍵按下’) global left_mouse_down_x, left_mouse_down_y left_mouse_down_x = event.x left_mouse_down_y = event.ydef left_mouse_up(event): # print(’鼠標(biāo)左鍵釋放’) global left_mouse_up_x, left_mouse_up_y left_mouse_up_x = event.x left_mouse_up_y = event.y corp_img(img_path, ’img/one_corp.png’, left_mouse_down_x, left_mouse_down_y, left_mouse_up_x, left_mouse_up_y)def moving_mouse(event): # print(’鼠標(biāo)左鍵按下并移動(dòng)’) global sole_rectangle global left_mouse_down_x, left_mouse_down_y moving_mouse_x = event.x moving_mouse_y = event.y if sole_rectangle is not None: canvas.delete(sole_rectangle) # 刪除前一個(gè)矩形 sole_rectangle = canvas.create_rectangle(left_mouse_down_x, left_mouse_down_y, moving_mouse_x, moving_mouse_y, outline=’red’)def right_mouse_down(event): # print(’鼠標(biāo)右鍵按下’) passdef right_mouse_up(event): # print(’鼠標(biāo)右鍵釋放’) passdef corp_img(source_path, save_path, x_begin, y_begin, x_end, y_end): if x_begin < x_end: min_x = x_begin max_x = x_end else: min_x = x_end max_x = x_begin if y_begin < y_end: min_y = y_begin max_y = y_end else: min_y = y_end max_y = y_begin save_path = os.path.abspath(save_path) if os.path.isfile(source_path): corp_image = Image.open(source_path) region = corp_image.crop((min_x, min_y, max_x, max_y)) region.save(save_path) print(’裁剪完成,保存于:{}’.format(save_path)) else: print(’未找到文件:{}’.format(source_path))if __name__ == ’__main__’: pass win = tk.Tk() frame = tk.Frame() frame.pack() screenwidth = win.winfo_screenwidth() screenheight = win.winfo_screenheight() img_path = ’img/one.png’ # img_path = ’img/bg.jpg’ # img_path = ’img/test.jpg’ # img_path = ’img/pic.gif’ image = Image.open(img_path) image_x, image_y = image.size if image_x > screenwidth or image_y > screenheight: print(’The picture size is too big,max should in:{}x{}, your:{}x{}’.format(screenwidth, screenheight, image_x, image_y)) img = ImageTk.PhotoImage(image) canvas = tk.Canvas(frame, width=image_x, height=image_y, bg=’pink’) i = canvas.create_image(0, 0, anchor=’nw’, image=img) canvas.pack() canvas.bind(’<Button-1>’, left_mouse_down) # 鼠標(biāo)左鍵按下 canvas.bind(’<ButtonRelease-1>’, left_mouse_up) # 鼠標(biāo)左鍵釋放 canvas.bind(’<Button-3>’, right_mouse_down) # 鼠標(biāo)右鍵按下 canvas.bind(’<ButtonRelease-3>’, right_mouse_up) # 鼠標(biāo)右鍵釋放 canvas.bind(’<B1-Motion>’, moving_mouse) # 鼠標(biāo)左鍵按下并移動(dòng) win.mainloop()

原圖one.png

python 實(shí)現(xiàn)圖片裁剪小工具

運(yùn)行

python 實(shí)現(xiàn)圖片裁剪小工具

python 實(shí)現(xiàn)圖片裁剪小工具

one_corp.png

python 實(shí)現(xiàn)圖片裁剪小工具

以上就是python 實(shí)現(xiàn)圖片裁剪小工具的詳細(xì)內(nèi)容,更多關(guān)于python 圖片裁剪的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 国产第一区二区三区在线观看 | 久爱综合 | 亚欧色视频在线观看免费 | 亚洲日本激情 | 欧美午夜网站 | 国产免费a级片 | 国产精品麻豆一区二区三区v视界 | 亚洲国产日韩欧美一区二区三区 | 99在线观看精品视频 | 日韩免费精品一级毛片 | 日韩一级欧美一级在线观看 | 国产精品久久久久免费a∨ 国产精品久久久久免费视频 | 中文字幕欧美一区 | 久草福利资源在线观看 | 亚洲精品国产一区二区三区四区 | 国产一级视频在线观看 | 农村寡妇一级毛片免费播放 | 女人成午夜大片7777在线 | 国产a精品三级 | 国产精品美女免费视频大全 | 美女在线网站免费的 | 欧美三级aaa | 国产精品久久久久无码av | 国产在线观看xxxx免费 | 亚洲欧美日韩国产vr在线观 | 中文字幕日本一区波多野不卡 | 亚洲国产成人va在线观看网址 | 在线播放国产一区二区三区 | 一级片aaa| 91在线成人 | 99久久精品自在自看国产 | 国产不卡精品一区二区三区 | xxx免费视频 | 欧美资源在线观看 | 久久精品福利视频 | 欧美成人全部免费观看1314色 | 九九九国产视频 | 九九成人免费视频 | 在线播放亚洲美女视频网站 | 日本a v 黄| 男女视频免费看 |