将灰度图像从PIL转换为QPixmap有什么问题?

时间:2013-03-06 12:13:16

标签: python pyqt pyqt4 python-imaging-library qpixmap

我的程序打开着名的Lena图像,然后将其转换为PIL图像,然后将其转换为QPixmap。

import sys
import cStringIO

from PyQt4 import QtGui, QtCore
from PIL import Image

class ImageLabel(QtGui.QLabel):
    def __init__(self, parent=None):
        QtGui.QLabel.__init__(self, parent)

        self.setGeometry(300, 300, 300, 350)
        self.setWindowTitle('Window')
        im = Image.open('Test_Images/Lena.bmp')

        self.bufor=QtCore.QBuffer()
        self.bufor.open(QtCore.QIODevice.ReadWrite)
        im.save(self.bufor, "PNG")

        strio = cStringIO.StringIO()
        strio.write(self.bufor.data())
        self.bufor.close()
        strio.seek(0)
        self.pil_image = Image.open(strio)
        self.pil_image.save('pil_image.png', 'PNG')
        data = self.pil_image.tostring()

        image = QtGui.QImage(data, self.pil_image.size[0], self.pil_image.size[1], QtGui.QImage.Format_Indexed8)
        pix = QtGui.QPixmap.fromImage(image)
        self.setPixmap(pix)

app = QtGui.QApplication(sys.argv)
imageLabel = ImageLabel()
imageLabel.show()

但是我倾斜并乘以图像Lena after transformation

奇怪的是:程序可以与某些类似的(灰度,8BPP)图像一起正常工作。 有什么不对?

0 个答案:

没有答案