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. Loading Large Images
Forum Updated to NodeBB v4.3 + New Features

Loading Large Images

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 842 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.
  • I Offline
    I Offline
    Infestor
    wrote on last edited by Infestor
    #1

    Hi,

    I want to load a large .png (~18000x10000), however the standard way does not work as the image is not loaded when using either QPIxmap/QImage in conjunction with their respecitve load functions.

    I also tried using QImageReader, but the reader also does not seem to load the image properly.

    
        QImageReader* reader = new QImageReader("largeImg.png");
      
        QImage img;
        QRect s;
        s.setX(0);
        s.setY(0);
        s.setWidth(1920);
        s.setHeight(1080);
        reader->setClipRect(s);
        img = reader->read();
        bool b = img.isNull() //true
    
    

    It works for smaller images (smaller in resolution only). Is there something else i have to change or do? Can/should i manually allocate the memory?

    JonBJ 1 Reply Last reply
    0
    • I Infestor

      Hi,

      I want to load a large .png (~18000x10000), however the standard way does not work as the image is not loaded when using either QPIxmap/QImage in conjunction with their respecitve load functions.

      I also tried using QImageReader, but the reader also does not seem to load the image properly.

      
          QImageReader* reader = new QImageReader("largeImg.png");
        
          QImage img;
          QRect s;
          s.setX(0);
          s.setY(0);
          s.setWidth(1920);
          s.setHeight(1080);
          reader->setClipRect(s);
          img = reader->read();
          bool b = img.isNull() //true
      
      

      It works for smaller images (smaller in resolution only). Is there something else i have to change or do? Can/should i manually allocate the memory?

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

      @Infestor Are you 64-bit?

      I 1 Reply Last reply
      0
      • JonBJ JonB

        @Infestor Are you 64-bit?

        I Offline
        I Offline
        Infestor
        wrote on last edited by
        #3

        @JonB Yes, also i dont think its a hardware problem (i.e. i have 32GB RAM, 6GB VRAM).

        Cobra91151C 1 Reply Last reply
        0
        • I Infestor

          @JonB Yes, also i dont think its a hardware problem (i.e. i have 32GB RAM, 6GB VRAM).

          Cobra91151C Offline
          Cobra91151C Offline
          Cobra91151
          wrote on last edited by Cobra91151
          #4

          @Infestor

          Hello!

          What is the size of this image? Also, do you load it from the app resource or drive?

          Christian EhrlicherC 1 Reply Last reply
          0
          • Cobra91151C Cobra91151

            @Infestor

            Hello!

            What is the size of this image? Also, do you load it from the app resource or drive?

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Even you set a clipRect() doesn't mean the image doesn't needed to be loaded into memory first. Some image formats may support this but even then the image plugin would need support for it (which png has not but jpeg does). So you need at 18000 *10000 * 4 bytes = ~686MB of free contiguous memory if it's a 32bit image.
            What does QImageReader::error() returns or do you see some errors on the command line?

            btw: why do you create reader on the heap? It's leaking...

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

            I 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              Even you set a clipRect() doesn't mean the image doesn't needed to be loaded into memory first. Some image formats may support this but even then the image plugin would need support for it (which png has not but jpeg does). So you need at 18000 *10000 * 4 bytes = ~686MB of free contiguous memory if it's a 32bit image.
              What does QImageReader::error() returns or do you see some errors on the command line?

              btw: why do you create reader on the heap? It's leaking...

              I Offline
              I Offline
              Infestor
              wrote on last edited by Infestor
              #6

              @Christian-Ehrlicher The error function returns invalidImageData after the read(). I dont get any other errors.

              There is no particular reason its on the heap, im just debugging, but im also deleting it later.
              The exact size of the image is 12300x7200, 404kb in png format (but the format doesnt really matter).

              In theory i could also split the image in multiple parts and then tranlate the individual parts in the scene accordingly, but im not yet sure how i could do that.

              Christian EhrlicherC 1 Reply Last reply
              0
              • I Infestor

                @Christian-Ehrlicher The error function returns invalidImageData after the read(). I dont get any other errors.

                There is no particular reason its on the heap, im just debugging, but im also deleting it later.
                The exact size of the image is 12300x7200, 404kb in png format (but the format doesnt really matter).

                In theory i could also split the image in multiple parts and then tranlate the individual parts in the scene accordingly, but im not yet sure how i could do that.

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                You mean InvalidDataError ? Please check what canRead() and format() returns. Also make sure QImageReader::allocationLimit() is large enough.

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

                I 1 Reply Last reply
                2
                • Christian EhrlicherC Christian Ehrlicher

                  You mean InvalidDataError ? Please check what canRead() and format() returns. Also make sure QImageReader::allocationLimit() is large enough.

                  I Offline
                  I Offline
                  Infestor
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher Setting the allocationLimit solves the issue. 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