首先PIL如果读取图片,应该使用
image = Image.open("fileName")
要想将image准换成pixmap然后使用label等空间显示的时候:可以使用
QtGui.QPixmap("filePath")
或者
QtGui.QPixmap.fromImage(image)
但有时候会出现argument 1 has unexpected type ‘…ImageFile’
这是由于PIL库没有引入正确,引入:
from PIL import Image
from PIL.ImageQt import ImageQt
如下
image = Image.open("fileName")
qimg = ImageQt(image)
pixmap = QtGui.QPixmap.fromImage(qimg )
即使用ImageQt()类过滤一下即可。
参考:https://stackoverflow.com/questions/35655755/qpixmap-argument-1-has-unexpected-type-pngimagefile