Answer the question
In order to leave comments, you need to log in
How to display a downloaded image from the Internet without intermediate saving to disk?
The program downloads a picture from the Internet using the requests library and displays it in a QLabel on the form.
Now the program does it like this ( python 3.5 ):
if res.status_code == 200:
path = "images/"+trek+"#1"+".jpg"
with open(path, "wb") as w:
w.write(res.content)
img1.setPixmap(QtGui.QPixmap(path))
Answer the question
In order to leave comments, you need to log in
try like this
# python2
# from StringIO import StringIO
from io import StringIO
if res.status_code == 200:
p = QtGui.QPixmap()
p.loadFromData(StringIO(res.content))
img1.setPixmap(p)
Well, you can pass a picture from memory - QPixmap::QPixmap(const char * const[] xpm)
Only before that you need to convert the image into an xpm array.
You can also: 1) first create a
QImage::QImage(uchar * data, int width, int height, Format format)
from a stream of bytes
2) then convert the resulting QImage into a QPixmap
bool QPixmap::convertFromImage(const QImage & image, Qt:: ImageConversionFlags flags = Qt::AutoColor)
3) pass it to img1.setPixmap
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question