当图像来自枕头时,尝试将Qpixmap设置为Qlabel时出现“分段错误(核心转储)”

问题描述 投票:0回答:1

所以我试图在我的UI上显示图像。我发现这样做的方法是将QPixmap设置为Qlabel。

qimg = QtGui.QImage("Lenna.png") # load QImage
pixImg = QtGui.QPixmap().fromImage(qimg) # convert QImage to QPixmap
self.imgLabel.setPixmap(pixImg) # add the QPixmap picture to GUI

这很好用,当我使用枕头来获取QImage qimg = PIL.Image.open("Lenna.png").toqimage()时会出现问题,那就是当我遇到段错误时。我已经尝试过任何枕头给我QImage,但这没有解决任何问题,我找不到任何其他可能有点相关的东西

python-3.x pyqt4 python-imaging-library
1个回答
1
投票

PIL.ImageQt有一个非常整洁,toqpixmap(img)方法,由于某种原因不在文件上。因此,我没有进行冗长的转换(当时,我认为这是唯一的方法),我只能做

img = Image.open("Lenna.png")
pixImg = ImageQt.toqpixmap(img)
self.imgLabel.setPixmap(pixImg)

这似乎工作得很好

© www.soinside.com 2019 - 2024. All rights reserved.