diff --git a/src/gui/imgview.py b/src/gui/imgview.py --- a/src/gui/imgview.py +++ b/src/gui/imgview.py @@ -31,7 +31,9 @@ class ImgView(ResizableCanvas): self.delete("all") if self._img: - img=self._img.resize((int(self._width),int(self._height))) + w,h=self._img.size + ratio=min(self._width/w, self._height/h) + img=self._img.resize((int(w*ratio),int(h*ratio))) self._tkImg=ImageTk.PhotoImage(img) # just to save the image from garbage collector self.create_image(self._width//2, self._height//2, anchor="center", image=self._tkImg) @@ -65,8 +67,7 @@ class ImgView(ResizableCanvas): # transform corners from show coordinates to real coordinates log.debug(self._corners.corners) self._boardGrid=Grid(self._corners.corners) - corners=[self._transformPoint(c) for c in self._corners.corners] - self._parent.sendMsg("setCorners",(corners,)) + self._parent.sendMsg("setCorners",(self.exportCorners(),)) self.redraw() @@ -75,6 +76,9 @@ class ImgView(ResizableCanvas): self.create_line(x-3,y-3,x+4,y+4,fill="#00ff00") self.create_line(x-3,y+3,x+4,y-4,fill="#00ff00") + def exportCorners(self): + return [self._transformPoint(c) for c in self._corners.corners] + def setUp(self): self.bind('<1>',lambda e: self.addCorner(e.x,e.y)) @@ -95,7 +99,7 @@ class ImgView(ResizableCanvas): wo,ho=self._img.size # o for original widthRatio=wo/w heightRatio=ho/h - self._imgSizeCoef=max(widthRatio,heightRatio) + imgSizeCoef=max(widthRatio,heightRatio) # shift compensates possible horizontal or vertical empty margins from unmatching aspect ratios - self._imgShift=EPoint(wo-w*self._imgSizeCoef,ho-h*self._imgSizeCoef)/2 - return EPoint(self.canvasx(point.x),self.canvasy(point.y)) * self._imgSizeCoef + self._imgShift + imgShift=EPoint(wo-w*imgSizeCoef,ho-h*imgSizeCoef)/2 + return EPoint(self.canvasx(point.x),self.canvasy(point.y)) * imgSizeCoef + imgShift