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. How to reduce the time cost of QImage::save() ?
Forum Updated to NodeBB v4.3 + New Features

How to reduce the time cost of QImage::save() ?

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

    I am using QImage to draw my model and I want to store all images in my computer.But I found that compared with drawing job itself , QImage::save() costs more time. In my example, drawing a 4K pic uses 20ms, but when you save it to your hard disk it costs 300ms. Is there any way to reduce the time cost of QImage::save() ?

    jsulmJ JonBJ 2 Replies Last reply
    0
    • MartinChan3M MartinChan3

      I am using QImage to draw my model and I want to store all images in my computer.But I found that compared with drawing job itself , QImage::save() costs more time. In my example, drawing a 4K pic uses 20ms, but when you save it to your hard disk it costs 300ms. Is there any way to reduce the time cost of QImage::save() ?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @MartinChan3 Just to understand your use case: why are 300ms a problem? Do you store each rendered frame as a picture?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      MartinChan3M 1 Reply Last reply
      2
      • MartinChan3M MartinChan3

        I am using QImage to draw my model and I want to store all images in my computer.But I found that compared with drawing job itself , QImage::save() costs more time. In my example, drawing a 4K pic uses 20ms, but when you save it to your hard disk it costs 300ms. Is there any way to reduce the time cost of QImage::save() ?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @MartinChan3
        Well, there is no reason saving it as a file should compare to the time taken to render it.

        How big is the image file, how fast is your "hard disk"?

        Try saving to device nul (Windows) or /dev/null (Linux), how does that compare? That should tell you whether it's processing time or disk time.

        I note that https://stackoverflow.com/questions/51377481/qimage-save-is-too-slow reports similar, but that user reported 20 seconds while you are reporting 300 milliseconds! It didn't get a solution, but see the comments, FWIW try compiling your app for release with optimization flags to see if that affects it?

        MartinChan3M 1 Reply Last reply
        1
        • jsulmJ jsulm

          @MartinChan3 Just to understand your use case: why are 300ms a problem? Do you store each rendered frame as a picture?

          MartinChan3M Offline
          MartinChan3M Offline
          MartinChan3
          wrote on last edited by
          #4

          @jsulm I am working on accelerating the saving job due to my project need to draw a sequence of frames and store them in my computer ( for 3d printing ).My job need about 2000 pictures and I want to accelerate the process ,so I do some research on time count and I found the save() costs the most time. That's why I care about the time cost.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Use a lower compression level and a format which is easy to compress.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            3
            • JonBJ JonB

              @MartinChan3
              Well, there is no reason saving it as a file should compare to the time taken to render it.

              How big is the image file, how fast is your "hard disk"?

              Try saving to device nul (Windows) or /dev/null (Linux), how does that compare? That should tell you whether it's processing time or disk time.

              I note that https://stackoverflow.com/questions/51377481/qimage-save-is-too-slow reports similar, but that user reported 20 seconds while you are reporting 300 milliseconds! It didn't get a solution, but see the comments, FWIW try compiling your app for release with optimization flags to see if that affects it?

              MartinChan3M Offline
              MartinChan3M Offline
              MartinChan3
              wrote on last edited by
              #6

              @JonB The image file is png and its size is 3940 * 2160(2k resolution) and due to png is a compressed format so the size is around 100kB.My hard disk is HDD.

              I tried optimized compile and it didn't have a obvious effect...

              JonBJ 1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                You can move the save out into an own thread but this should be your last resort esp. since you have to make sure that you don't go out of memory in your case.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                2
                • MartinChan3M MartinChan3

                  @JonB The image file is png and its size is 3940 * 2160(2k resolution) and due to png is a compressed format so the size is around 100kB.My hard disk is HDD.

                  I tried optimized compile and it didn't have a obvious effect...

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @MartinChan3
                  So as per @Christian-Ehrlicher's answer the time is presumably taken to compress the image for saving, which does not apply when displaying the image.

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi
                    I would also check out using a RAMDISk to write on if you have memory for it.
                    Write speed is around 6000 MB/s so it's much faster than an HDD.
                    https://sourceforge.net/projects/imdisk-toolkit/

                    But if file is only 100 kb, then it seems like as mentioned by the others, its indeed the compression
                    that takes time. As even a HHD can write 100 kb fast :)

                    1 Reply Last reply
                    1

                    • Login

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