Convert RGBA8888 buffer to jpeg buffer in memory



  • Hi,
    I've a buffer that contains RGBA888 ,I want to create another buffer that hold the jpeg format according to RGBA buffer with header and data.
    I would appreciate any idea.


  • Moderators

    Hi!

        // prepare image in RGBA8888 format
        QImage img(600, 400, QImage::Format_RGBA8888);
        {
            img.fill(QColor("white"));
            QPainter painter(&img);
            painter.drawLine(0, 0, 600, 400);
            painter.drawLine(0, 400, 600, 0);
        }
    
        // save image as JPEG to buffer
        QByteArray ba; // buffer uses ba as its storage
        QBuffer buf(&ba); // we'll use buf as QIODevice
        buf.open(QIODevice::WriteOnly);
        img.save(&buf, "JPEG");
    


  • Dear @Wieland ,
    Thank you so much.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.