如何从pyqt5中的字节设置qpixmap
如何从图像文件的字节中设置标签的PixMap (“ example.bmp”)
。我几乎整天都在搜索和尝试,但是找不到解决方案。
我想设置标签的像素以显示“ bytes ”源的图像,但我不想将图像文件保存在磁盘上。有没有办法解决此问题?
或者,也许有一种方法可以将字节的顺序保存到内存中的文件example2.bmp
中(buffer或_io.bufferedreader)?
这是我的代码
with open("example.bmp", 'rb') as file:
header = file.read(53)
pixeldata = file.read()
images = header+pixel #Bytes sequence of example.bmp file
pixmap = QPixmap.loadFromData(images)
self.label.setPixmap(pixmap)
How to set Pixmap of label from a bytes of an images file ("example.bmp")
. I have searched and tried every way almost all day, but I can't find a solution.
I want to set the Pixmap of a label to display the image from the "Bytes" source, but I don't want to save the image file on disk. Is there a way to fix this problem?
Or maybe is there a way how to save the sequence of bytes into a file example2.bmp
in memory (buffer or _io.BufferedReader)?
Here is my code
with open("example.bmp", 'rb') as file:
header = file.read(53)
pixeldata = file.read()
images = header+pixel #Bytes sequence of example.bmp file
pixmap = QPixmap.loadFromData(images)
self.label.setPixmap(pixmap)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,我从错误中找到了解决方案。感谢@musicamante提醒我。
Finally, i found solution from my mistakes. Thanks to @musicamante for reminding me.