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. [SOLVED]Does Qt provide a way to determine the size of an PNG image file before save it?
QtWS25 Last Chance

[SOLVED]Does Qt provide a way to determine the size of an PNG image file before save it?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.5k Views
  • 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.
  • A Offline
    A Offline
    antonyprojr
    wrote on last edited by
    #1

    I'm currently working with QImage to create a PNG file with the highest compression available (quality=0).

    That process may spend some time, depending of the dimensions of the image.

    I'm saving it in a separete thread, and on the main thread i want to have a progressbar showing the progress of the save task, I know that i can use QFile::size() to determine the number of generated bytes, but i need to know how much bytes the image will have and with that information calculate the progress of the save task.

    How can I do that?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      BlastDV
      wrote on last edited by
      #2

      In my experience, I've found that using a progress bar to show every step in the process may end by making it slower than it should be; it is better to update the progress bar every n steps (where n may be the result of TotalSteps/AnyNumberYouWant) so you don't overload Qt with output functions. With this in mind and as matter of efficiency, users may not want to know how many bytes of the total size are done, instead, if you're using loops to process your QImage, you may update your progress bar every n iterations and it will provide the same result to users.

      I hope I've helped you somehow :)

      (8) Just live your life blind like me (8)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        antonyprojr
        wrote on last edited by
        #3

        Thanks @BlastDV! But to use loops I need to split the save task into peaces, how can I do that?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BlastDV
          wrote on last edited by
          #4

          You may just create a "global" QImage and assign chunks to every thread. So every one of them copies its processed data to the corresponding chunk of the original QImage and after you joined all of your threads, you simply save that one.

          For example, every thread takes a row from the original QImage and then return the processed data to the global output one.

          But thinking of PNGs, I don't remember how you manage compression with that extension, I assume you know it, but the proccess may be similar since you need to remove repeated colors or things like that, depending on the compression method you're using. The idea I'm giving to you may be the most basic one, but It may work for an initial approach.

          (8) Just live your life blind like me (8)

          1 Reply Last reply
          0
          • A Offline
            A Offline
            antonyprojr
            wrote on last edited by
            #5

            Thanks again @BlastDV! I will do that!

            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