我正在嘗試使用以下測試應用程序顯示PGM文件。該代碼適用於PNG文件,但不適用於PGM:如何在QGraphicsView中顯示PGM文件?
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import Image
import ImageQt
class MyView(QGraphicsView):
def __init__(self):
QGraphicsView.__init__(self)
self.scene = QGraphicsScene(self)
self.setScene(self.scene)
img = Image.open('test.pgm') # works with 'test.png'
self.imgQ = ImageQt.ImageQt(img)
pixmap = QPixmap.fromImage(self.imgQ)
self.scene.addPixmap(pixmap)
if __name__ == '__main__':
app = QApplication(sys.argv)
view = MyView()
view.show()
sys.exit(app.exec_())
如何在QGraphicsView中顯示PGM文件?
是的我檢查過img是否正確加載。 OP代碼是否適用於PGM文件? – itISiBOWMAN 2012-07-25 20:55:40