QImage real bytes count



  • Hello,

    how to retrieve the amount of bytes for an object of type QImage so if it would be saved onto disk the file size will have the same amount of bytes?


  • Moderators

    how should this be possible since it depends in which format you save the file on the disk?



  • PNG


  • Moderators

    it's still not possible directly from QImage ;)

    You would first save it to this format and check it's resulting data size. This may block your application depending on the size of the image. If so you may want to do this in another thread.

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

    int fileSize = ba.size();
    @



  • It is still a synchronous job.
    [quote author="raven-worx" date="1379919631"]it's still not possible directly from QImage ;)

    You would first save it to this format and check it's resulting data size. This may block your application depending on the size of the image. If so you may want to do this in another thread.

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

    int fileSize = ba.size();
    @[/quote]


  • Moderators

    [quote author="silex92" date="1379920609"]It is still a synchronous job.
    [/quote]
    Yes as i said!
    If you do want it to do asynchronously use another thread using signals and slots with a queued connection.


Log in to reply
 

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