pyqt5不熟,百度看大佬示例,搞了半小時,記錄一下
外部鏈接:
https://blog.csdn.net/qq_32973061/article/details/81139689
https://blog.csdn.net/ccchen706/article/details/71425653
from PyQt5.QtWidgets import QApplication, QLabel
from PyQt5.QtGui import QImage, QPixmap
import numpy as np
if __name__ == '__main__':
app = QApplication(sys.argv)
h, w = 300, 600
im = np.random.randint(0, 255, [h, w, 3], np.uint8)
a = QLabel()
a.resize(w, h)
# 注意下面QtGui.QImage的第四個參數,意思爲圖像每行有多少個字節,不設定時,圖像有時會歪,所以一定要設定
im = QImage(im.data, im.shape[1], im.shape[0], im.shape[1]*3, QImage.Format_RGB888)
pix = QPixmap(im).scaled(a.width(), a.height())
a.setPixmap(pix)
a.show()
exit(app.exec_())