On 2024-01-26 13:55, Alexander Carôt via Interest wrote:
Hi all,

I have a raw image:

QImage *img = new QImage(imgBufferOut,
                          reso.width(),
                          reso.height(),
                          QImage::Format_RGB888);


that I convert to JPG via


QBuffer bufferJpeg;
bufferJpeg.open(QIODevice::WriteOnly);
img->save(&bufferJpeg, "JPEG");
finalJpg = bufferJpeg.data();


Now I transfer the content finalJpg in form of a Base64 encoded QString via a 
websocket to a web browser. Within the browser it should be displayed via


const imageDataUri ="data:image/jpeg;base64,"  + msg.jpgBuffer;
videoImage.src = imageDataUri;


Now my question is how should I create the required sting ? I tried:


QString jpgBufferString( finalJpg.data() );
QString encodedString = jpgBufferString.toUtf8().toBase64();


but this does not decode the image and simply shows the broken image icon in 
the browser.

Can anyone help with this ?

Thanks in advance,
best

Alex


Hi, maybe passing JPG through fromUtf8() and toUtf8() munges it too much, what happens if you simplify, instead of:

QString jpgBufferString( finalJpg.data() );
QString encodedString = jpgBufferString.toUtf8().toBase64();

try:
QString encodedString = finalJpg.data().toBase64();

_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to