Hello World / plɹoM ollǝH

Programmers Live in Vain

QPixmap from PIL Image

PILで作った画像を表示するときに便利

f:id:dungeonneko:20150719142409p:plain

# conding: utf-8
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from PIL import Image, ImageQt

# entry point
if __name__ == '__main__':
    myapp = QApplication(sys.argv)

    # PILで画像読み込み
    img = Image.open('temp.png')

    # Qtで表示
    pm = QPixmap.fromImage(ImageQt.ImageQt(img))
    lbl = QLabel()
    lbl.setPixmap(pm)
    lbl.show()

    sys.exit(myapp.exec_())