소스 검색

Scale image to fit area

Michael Pitidis 13 년 전
부모
커밋
db15457e46
1개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 12 1
      labelme.py

+ 12 - 1
labelme.py

@@ -148,9 +148,20 @@ class MainWindow(QMainWindow, WindowMixin):
     def showImage(self):
         if self.image.isNull():
             return
-        self.imageWidget.setPixmap(QPixmap.fromImage(self.image))
+        self.imageWidget.setPixmap(self.scaled(QPixmap.fromImage(self.image)))
         self.imageWidget.show()
 
+    def resizeEvent(self, event):
+        if self.imageWidget and self.imageWidget.pixmap():
+            self.imageWidget.setPixmap(self.scaled(self.imageWidget.pixmap()))
+        super(MainWindow, self).resizeEvent(event)
+
+    def scaled(self, pixmap):
+        width = self.centralWidget().width()
+        height = self.centralWidget().height()
+        return pixmap.scaled(width, height,
+          Qt.KeepAspectRatio, Qt.SmoothTransformation)
+
     def closeEvent(self, event):
         # TODO: Make sure changes are saved.
         s = self.settings