Hooder Hooder - 2 months ago 10
C++ Question

Saving an image from a label to disc

I've just spent 3 hours with the relevant documentation, but I don't understand it (I'm a complete noobie). I have a jpg image in a label (the label is named 'screen') - and I simply want to save it to disc giving it a generated filename, which I've got. I've looked at Qimage, and QPixmap, but it's all beyond me. How can I get the image which is being displayed on the label, and save it to disc? It must be very easy, but I can not do it. The problem seems to be getting the image from the label into a QPixmap or a QImage so that I can save it. Please help.

Answer

It's very easy. Example:

const QPixmap* pix = myLabel->pixmap();
if(pix)
    pix->save("save/path/img.jpg");
Comments