简体   繁体   English

PySide QImage在OS X上产生质量差的像素化渲染

[英]PySide QImage produces poor quality pixelated rendering on OS X

In a PySide application I'm developing, I've come across an extremely frustrating issue that I have spent days trying to solve. 在我正在开发的PySide应用程序中,我遇到了一个非常令人沮丧的问题,我花了几天的时间来解决。 I subclassed QLabel and set a QPixmap , which can be scaled to any desired width while maintaining the aspect ratio. 我对QLabel了子类化,并设置了QPixmap ,可以在保持纵横比的同时将其缩放到任何所需的宽度。 I understand that the scaledToWidth and scaledToHeight methods are bound to slightly distort the image but the distortion was not to the magnitude I expected. 我知道scaledToWidthscaledToHeight方法势必会使图像稍有变形,但失真未达到我预期的程度。 I've attempted both SmoothTransformation AND FastTransformation , the latter yielding more sharp and pixelated but less blurred and ugly. 我尝试了SmoothTransformationFastTransformation ,后者产生的图像更清晰锐利,但模糊和丑陋的程度更低。 I've tried every acceptable image format and they all exhibit the same horrible rendering. 我尝试了每种可接受的图像格式,它们都呈现出相同的可怕渲染。 Below is my QLabel subclass which holds the image: 以下是我的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())

What the image looks like with SmoothTransformation : 使用SmoothTransformation图像的外观:

在此处输入图片说明

Here is the original Image: 这是原始图像:

在此处输入图片说明

Try setting the graphics system to native. 尝试将图形系统设置为本机。

from PySide import QtCore, QtGui
QtGui.QApplication.setGraphicsSystem('native')

This may improve the rendering but 'native' can be buggy on OSx. 这可能会改善渲染效果,但是“本机”在OSx上可能有问题。 Better support is provided in Qt5 which is being included in pyside2 (under development). pyside2中包含的Qt5(正在开发中)提供了更好的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM