1
目前我的應用程序中有一個縮放功能,效果很好,但是我希望實際縮放框是一個圓形。下面是目前變焦的樣子: 創建圓形圖像PIL Tkinter
放大後的矩形是當鼠標指針位置,和周圍的區域被放大,但我怎麼能做出這種放大對象的圓,而不是一個正方形?這裏是我的代碼:
def zoom(self, event):
if(event.delta > 0):
if self.zoomValue != 4 : self.zoomValue += 1
elif(event.delta < 0):
if self.zoomValue != 0 : self.zoomValue -= 1
self.crop(event)
def crop(self, event):
if self.zimg_id: self.canvasLower.delete(self.zimg_id)
if (self.zoomValue) != 0:
x, y = event.x, event.y
if self.zoomValue == 1:
tmp = self.orig_img.crop((x-45, y-30, x+45, y+30))
elif self.zoomValue == 2:
tmp = self.orig_img.crop((x-30, y-20, x+30, y+20))
elif self.zoomValue == 3:
tmp = self.orig_img.crop((x-15, y-10, x+15, y+10))
elif self.zoomValue == 4:
tmp = self.orig_img.crop((x-6, y-4, x+6, y+4))
size = 200, 200
# crop tmp somehow to make the image a circle? maybe?
self.zimg = ImageTk.PhotoImage(tmp.resize(size))
self.zimg_id = self.canvasLower.create_image(event.x, event.y, image=self.zimg)
請問您的圖像有一個alpha通道?通常圓形圖像只是角落透明的方形圖像。 – ballsatballsdotballs