Qimage保存低质量

2024-04-19 09:21:06 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我有一个文件采集器,采取一个图像,并保存为一个jpg,但它看起来很可怕。请帮帮我,我不知道为什么看起来不好。在

    def getfile(self):
        fname = QFileDialog.getOpenFileName(self, 'Open file',"","Image files (*.jpg *.gif)")
        print(fname)
        img = QImage(fname)

        img = img.convertToFormat(QImage.Format_Indexed8,Qt.ThresholdDither|Qt.AutoColor)
        newname = 'Old/'+ time.strftime("img%Y%m%d%H%M%S") + '.jpg'
        print(newname)
        os.rename('Background.jpg', newname)
        img.save('Background.jpg', "jpg", 100)

我把它设为100,但还是没用

enter image description here之前

enter image description here之后

这样做的目的是允许用户添加图像作为背景,但是如果图像是png或bmp,则将其转换为jpeg,以便使用背景.jpg““


Tags: 文件图像selfimgdefqtfnamejpg