[英]PySide QImage produces poor quality pixelated rendering on OS X
在我正在开发的PySide应用程序中,我遇到了一个非常令人沮丧的问题,我花了几天的时间来解决。 我对QLabel
了子类化,并设置了QPixmap
,可以在保持纵横比的同时将其缩放到任何所需的宽度。 我知道scaledToWidth
和scaledToHeight
方法势必会使图像稍有变形,但失真未达到我预期的程度。 我尝试了SmoothTransformation
和FastTransformation
,后者产生的图像更清晰锐利,但模糊和丑陋的程度更低。 我尝试了每种可接受的图像格式,它们都呈现出相同的可怕渲染。 以下是我的QLabel
子类,其中包含图像:
class JXImageView(QLabel):
def __init__(self, parent, window, image, select_image, identifier, scaled_width=60, x=0, y=0):
super(JXImageView, self).__init__(parent)
self.move(x, y)
pxm = QPixmap().fromImage(QImage(image))
pxm = pxm.scaledToWidth(scaled_width, Qt.SmoothTransformation)
self.setPixmap(pxm)
self.setFixedSize(pxm.size())
使用SmoothTransformation
图像的外观:
这是原始图像:
尝试将图形系统设置为本机。
from PySide import QtCore, QtGui
QtGui.QApplication.setGraphicsSystem('native')
这可能会改善渲染效果,但是“本机”在OSx上可能有问题。 pyside2中包含的Qt5(正在开发中)提供了更好的支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.