Displaying Image (in bytes) in PyQt

时间秒杀一切 提交于 2019-11-30 09:45:47

问题


I need to know how to display an image in bytes in GUI. I am taking an image from google static map API with .content I get the image in bytes like this:

import requests

a = requests.get('https://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400')
print(a.content)

I want to display it in the interface i am creating. I know that i can save the bytes in an image and then create a QPixmap loading the image and adding it to a scene or maybe a Qlabel, but can I display the image in the interface without saving it?

I would appreciate any help.


回答1:


You will want to use QPixmap.loadFromData().

qp = QPixmap()
qp.loadFromData(my_bytes)


来源:https://stackoverflow.com/questions/31096325/displaying-image-in-bytes-in-pyqt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!