Home > Enterprise >  How to convert png image into base 64 format in Qt
How to convert png image into base 64 format in Qt

Time:09-17

I want to convert a "sky.png" image into base 64 format in cpp using Qt. I found the following code in Qt documentation, but don't get how to get the base 64 format. How to convert image into base 64 format?

QImage image;
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "PNG");
qDebug()<<"buffer"<<&buffer;

CodePudding user response:

Bro, you are almost there: you just need to: write the image into the buffer and then from the buffer get the data as Bse 64...

like:

QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
QImage qp(":/resources/images/foo.png");
qp.save(&buffer, "PNG");
QString encoded = buffer.data().toBase64();

CodePudding user response:

enter image description here

Here is the image which I am trying to convert

  • Related