以下是完整源代码
""" 用海龟进行模糊处理图像.py """ from PIL import Image,ImageTk,ImageFilter from turtle import Turtle,Screen,TK def process(value): """对图像进行高斯模糊处理""" gf = ImageFilter.GaussianBlur(float(value))# 形成高斯模糊滤镜 blurred_image = im.filter(gf) # 进行高期模糊 blurred_image = ImageTk.PhotoImage(blurred_image)# 包装成PhotoImage对象 screen._shapes['blank']._data = blurred_image # 修改空白造型的_data值 screen.update() # 更新屏幕显示 screen = Screen() screen.setup(480,640) root = screen._root pic = Turtle(shape='blank') TK.Scale(root, from_=0, to=100, length=400,tickinterval=5, orient=TK.HORIZONTAL, command=process).pack() im = Image.open('notepad.jpg') process(0) screen.mainloop()
发表评论