变焦时低分辨率

时间:2014-04-26 18:20:02

标签: python image pyqt

我最近在我的应用中实现了一个图像查看器,基于此处的示例:

MousePressEvent, position offset in QGraphicsView"

以下是我的QGraphicsView子类的编写方式:

from PyQt4 import QtGui, QtCore


class GraphicsViewPerso(QtGui.QGraphicsView):


    def __init__(self,  parent = None):

        super(GraphicsViewPerso, self).__init__(parent)
        self.parent = parent


    def wheelEvent(self, event):

        super(GraphicsViewPerso, self).wheelEvent(event)

        self.setTransformationAnchor(GraphicsViewPerso.AnchorUnderMouse)
        factor = 1.2
        if event.delta() < 0 :
            factor = 1.0 / factor
        self.scale(factor, factor)

但我注意到这个解决方案,即使我的照片是高分辨率的,我的渲染也很糟糕。我可以放大,但图片不清晰,就像我加载了它的低分辨率版本一样。

我知道为什么会有这种行为?

1 个答案:

答案 0 :(得分:0)

好的,过了一会儿,我终于找到了问题所在。我正在显示这样的图片:

     w_vue, h_vue = self.vision.width(), self.vision.height() 
    self.current_image = QtGui.QImage(path_mosaic)
    self.pixmap = QtGui.QPixmap.fromImage(self.current_image.scaled(w_vue, h_vue,
                                QtCore.Qt.KeepAspectRatio, 
                                QtCore.Qt.SmoothTransformation)) 

    w_pix, h_pix = self.pixmap.width(), self.pixmap.height()

    self.scene = QtGui.QGraphicsScene()

    self.scene.setSceneRect(0, 0, w_pix , h_pix - 10)
    self.scene.addPixmap(self.pixmap)
    self.vision.setScene(self.scene)

虽然像素图声明应该是这样,但只需:         self.pixmap = QtGui.QPixmap(self.current_image)

与QGraphicsView没什么关系。