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. QImage: out of memory, returning null image
QtWS25 Last Chance

QImage: out of memory, returning null image

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 5 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.
  • D Offline
    D Offline
    Daniel Santos
    wrote on last edited by
    #1

    Hello,

    I am making a view that displays a map, made up of square tiles. Each tile is an image has 1070 x 1070 pixels. The view only loads the tiles that are visible in the view.
    When my app starts only one tile is visible. But nothing is displayed because of the error in the subject of this post.
    I converted the image to a TIFF with no compression from a PNG, and it's size is 3.33 Megabytes. Does not seem to be very big by todays starndards. I am on a windows machine with windows 10 and have 16GB Memory.

    What can I do ?

    Thanks,
    Regards

    1 Reply Last reply
    0
    • hskoglundH Online
      hskoglundH Online
      hskoglund
      wrote on last edited by
      #2

      Hi, just guessing but if your Qt app is 32-bit, try rebuilding it as a 64-bit app (that'll increase the virtual memory size).

      1 Reply Last reply
      1
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        When my app starts only one tile is visible.

        Only one visible, but how many tiles does the program actually try to load? Is it caching everything?

        What can I do?

        You could share a self-contained example program that demonstrates the issue. It matters what the source data is and how exactly you try to load it. It also matters what Qt version. This, for example, works fine for me:

        #include <QCoreApplication>
        #include <QImage>
        #include <QDebug>
        
        int main(int argc, char **argv) {
                QCoreApplication app(argc, argv);
                QImage image("test.png");
                qDebug() << image;
                return 0;
        }
        

        for an input file:

        $ convert -size 1070x1070 -depth 8 plasma:fractal  test.png
        $ identify test.png 
        test.png PNG 1070x1070 1070x1070+0+0 8-bit sRGB 1.91768MiB 0.000u 0:00.000
        

        outputs:

        QImage(QSize(1070, 1070),format=QImage::Format_RGB32,depth=32,devicePixelRatio=1,bytesPerLine=4280,sizeInBytes=4579600)
        

        (Linux, 64-bit, gcc, Qt 5.12.8)

        1 Reply Last reply
        2
        • D Offline
          D Offline
          Daniel Santos
          wrote on last edited by
          #4

          Hello,

          I slimmed down my code, and commented the following in it :

          QTransform flipVertical;
          flipVertical.scale(1*metadata->scale, -1*metadata->scale);
          pixmapAt = pixmapAt->transformed(flipVertical);
          
          

          And the error disappeared and my images are being loaded.
          So what I need to do now is preprocess them to make the flip and then use them in the code.
          Anyway, this is strange, the transform takes up that much memory ?

          Thanks,
          Regards

          1 Reply Last reply
          0
          • C Offline
            C Offline
            ChrisW67
            wrote on last edited by ChrisW67
            #5

            So you get the reported error when transforming a QPixmap/QImage rather than loading an QImage.

            What is the value of metadata->scale? If this is, for example, 10 then your image grows quite a lot. Worse, if metadata->scale is uninitialised then the transformed image might grow to unmanageable size.

            QPixmap is limited to 16384x16384. The maximum QImage size is governed by the storage required, which cannot exceed MAX_INT and must be allocatable as a single block. If you are transforming a QPixmap then it uses an internal QImage IIRC.

            1 Reply Last reply
            3
            • D Offline
              D Offline
              Daniel Santos
              wrote on last edited by
              #6

              Hi and thanks for the swift answer,

              I am using the value 2000 in the scale so 1078x2000 = 2156000 which is greater than 16384. That's it, isn't it ?

              Regards

              JonBJ 1 Reply Last reply
              0
              • D Daniel Santos

                Hi and thanks for the swift answer,

                I am using the value 2000 in the scale so 1078x2000 = 2156000 which is greater than 16384. That's it, isn't it ?

                Regards

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

                @Daniel-Santos
                Unless I misunderstand, @ChrisW67 only said it must not be greater than 16384 * 16384. Both your numbers are comfortably less.

                EDIT I did indeed misunderstand what @Daniel-Santos is doing :)

                J.HilkJ 1 Reply Last reply
                0
                • JonBJ JonB

                  @Daniel-Santos
                  Unless I misunderstand, @ChrisW67 only said it must not be greater than 16384 * 16384. Both your numbers are comfortably less.

                  EDIT I did indeed misunderstand what @Daniel-Santos is doing :)

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  @JonB I think you misunderstood @Daniel-Santos
                  his metadata->scale is 2000, therefore any image bigger than 8x8 will run out of memory ;)


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  JonBJ 1 Reply Last reply
                  0
                  • J.HilkJ J.Hilk

                    @JonB I think you misunderstood @Daniel-Santos
                    his metadata->scale is 2000, therefore any image bigger than 8x8 will run out of memory ;)

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

                    @J-Hilk Ooohhhhhh :) He is scaling up by 2,000x? He'd better have just 8x8s then? I get it, thank you.

                    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