Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get the size of jpg file of QImage file before saving it.
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 723 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samdol
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved