我想从QLabel中获取图像数据并将其存储到PostgreSQL数据库中,但我不能直接将其存储为QPixmap,首先需要将其转换为字节。这就是我想知道的内容。
我已经阅读了pyqt5文档的部分内容,特别是QImage和QPixmap的部分,但没有找到我要寻找的东西。
from PyQt5 import QtWidgets, QtGui
class Widget(QtWidgets.QWidget):
def __init__(self):
super().__init__(None)
self.label = QtWidgets.QLabel(self)
self.label.setPixmap(QtGui.QPixmap("ii_e_desu_ne.jpg"))
self.setFixedSize(400,400)
self.label.setFixedSize(200, 200)
self.label.move(50, 50)
self.show()
#All is set now i want to convert the QPixmap instance's image
#into a byte string
app = QtWidgets.QApplication([])
ventana = Widget()
app.exec_()
QPixmap
为numpy.ndarray
的此答案应该有效。只需省略将数据从字节字符串转换为numpy数组的最后一步即可。 - CodeSurgeon