[Interest] displaying Qt-coded JPEG image in browser

Alexander Carôt alexander_carot at gmx.net
Fri Jan 26 13:55:59 CET 2024


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

--
http://www.carot.de
Email : Alexander at Carot.de
Tel.: +49 (0)177 5719797



More information about the Interest mailing list