在PyQt中显示图像(以字节为单位) [英] Displaying Image (in bytes) in PyQt
本文介绍了在PyQt中显示图像(以字节为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道如何在GUI中以字节为单位显示图像。
我正在使用.content从Google静态地图API中获取图像,我以如下字节形式获取图像:
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)
我想在我正在创建的界面中显示它。
我知道我可以将字节保存在图像中,然后创建一个 QPixmap
加载图像并将其添加到场景中,或者也许添加到 Qlabel
,但是我可以在不保存图像的情况下在界面中显示图像吗?
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?
我将不胜感激。
推荐答案
您将要使用 QPixmap.loadFromData()
。
You will want to use QPixmap.loadFromData()
.
qp = QPixmap()
qp.loadFromData(my_bytes)
这篇关于在PyQt中显示图像(以字节为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文