Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying Image (in bytes) in PyQt

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.

like image 361
Polo D. Vargas Avatar asked Dec 04 '25 14:12

Polo D. Vargas


1 Answers

You will want to use QPixmap.loadFromData().

qp = QPixmap()
qp.loadFromData(my_bytes)
like image 105
three_pineapples Avatar answered Dec 07 '25 07:12

three_pineapples



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!