-3

I am beginning with Qt

I need to convert a Base64 string of a Jpeg image into a Qimage and display it in a QLabel

Can someone please direct me as to how to go about doing this?

TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
SAHLA
  • 83
  • 1
  • 7
  • 3
    I think people are being a bit harsh to the OP here in marking this down. He or she is clearly new to SO and it was clear as to what they were asking, even with the unnecessary Base64 jpeg added to the question. – TheDarkKnight Jan 08 '15 at 09:20
  • I am sorry for I could not make the question clear. I was trying to assign the base64 value of a jpeg picture on to a QByteArray variable. The string was more than 200,000 characters in length. The assignment was not working properly. Thanks Merlin069 for suggestions. – SAHLA Jan 08 '15 at 10:02

2 Answers2

5

Well there is QByteArray and QImage. QImage has loadFromData method which can be used with base64 encoded data.

QByteArray imageData = QByteArray::fromBase64("YourBase64EncodedString");
QImage img;
if (img.loadFromData(imageData)) {
    // show this label somewhere.
    QLabel label;
    label->setPixmap(QPixmap::fromImage(img)); 
}

Here you can find more information on how to read and write images

A more complete example can be found in my github repository. I wrote this app some years ago to restore base64 encoded images from e-mails that were accidentally deleted.

Christian Rapp
  • 1,853
  • 24
  • 37
1

You can do it with QByteArray and QImage::loadFromData(const QByteArray & data)

  QByteArray barray = QByteArray::fromBase64("base64 string");
  QImage image;
  image.loadFromData(barray);
shinichy
  • 81
  • 1
  • 2