【发布时间】:2019-08-08 03:26:09
【问题描述】:
我想从 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_()
【问题讨论】:
-
This answer 用于将
QPixmap转换为numpy.ndarray应该可以工作。只需省略将数据从字节字符串转换为 numpy 数组的最后一步。
标签: python pyqt pyqt5 qimage qpixmap