使用标签显示图像
displaying image using a label
我已将一个 numpy 数组转换为一个像素图,以便在我的 GUI 中的标签上显示它。当我 运行 程序时,GUI 出于某种原因关闭(没有错误消息)。
height, width = input_image.shape
bytesPerLine = 3 * width
qImg = QtGui.QImage(input_image.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888)
pixmap01 = QtGui.QPixmap.fromImage(qImg)
self.pixmap_image = QtGui.QPixmap(pixmap01)
self.ui.label_imageDisplay.setPixmap(self.pixmap_image)
self.ui.label_imageDisplay.setAlignment(QtCore.Qt.AlignCenter)
self.ui.label_imageDisplay.setScaledContents(True)
self.ui.label_imageDisplay.setMinimumSize(1,1)
self.ui.label_imageDisplay.show()
试试这个:
from PyQt5 import QtWidgets, QtGui, QtCore
from scipy.ndimage import imread
import sys
app = QtWidgets.QApplication(sys.argv)
input_image = imread({your filename})
height, width, channels = input_image.shape
bytesPerLine = channels * width
qImg = QtGui.QImage(input_image.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888)
pixmap01 = QtGui.QPixmap.fromImage(qImg)
pixmap_image = QtGui.QPixmap(pixmap01)
label_imageDisplay = QtWidgets.QLabel()
label_imageDisplay.setPixmap(pixmap_image)
label_imageDisplay.setAlignment(QtCore.Qt.AlignCenter)
label_imageDisplay.setScaledContents(True)
label_imageDisplay.setMinimumSize(1,1)
label_imageDisplay.show()
sys.exit(app.exec_())
我已将一个 numpy 数组转换为一个像素图,以便在我的 GUI 中的标签上显示它。当我 运行 程序时,GUI 出于某种原因关闭(没有错误消息)。
height, width = input_image.shape
bytesPerLine = 3 * width
qImg = QtGui.QImage(input_image.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888)
pixmap01 = QtGui.QPixmap.fromImage(qImg)
self.pixmap_image = QtGui.QPixmap(pixmap01)
self.ui.label_imageDisplay.setPixmap(self.pixmap_image)
self.ui.label_imageDisplay.setAlignment(QtCore.Qt.AlignCenter)
self.ui.label_imageDisplay.setScaledContents(True)
self.ui.label_imageDisplay.setMinimumSize(1,1)
self.ui.label_imageDisplay.show()
试试这个:
from PyQt5 import QtWidgets, QtGui, QtCore
from scipy.ndimage import imread
import sys
app = QtWidgets.QApplication(sys.argv)
input_image = imread({your filename})
height, width, channels = input_image.shape
bytesPerLine = channels * width
qImg = QtGui.QImage(input_image.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888)
pixmap01 = QtGui.QPixmap.fromImage(qImg)
pixmap_image = QtGui.QPixmap(pixmap01)
label_imageDisplay = QtWidgets.QLabel()
label_imageDisplay.setPixmap(pixmap_image)
label_imageDisplay.setAlignment(QtCore.Qt.AlignCenter)
label_imageDisplay.setScaledContents(True)
label_imageDisplay.setMinimumSize(1,1)
label_imageDisplay.show()
sys.exit(app.exec_())