Get the size of jpg file of QImage file before saving it.



  • Hi,

    I could get the target QImage from source QImage by the following snippet.

        QByteArray ba;
        QBuffer buffer(&ba);
        buffer.open(QIODevice::WriteOnly);
        QImageWriter writer;
        writer.setDevice(&buffer);
        writer.setFormat("jpg");
        writer.setQuality(88);
        writer.write(image_source);
        image_target.loadFromData(ba);
    

    Is there any way which tells me how much kilo byte this jpg file would take up even before I save it to disk?
    I tried to use buffer.data.size(), but it seems give me the size before jpg compression.


  • Lifetime Qt Champion

    Hi,

    No, because it depends on what your image contains.

    By the way, why are you using such a complicated way to copy data from image_source to image_target ?


Log in to reply
 

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