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::loadFromData failing
Qt 6.11 is out! See what's new in the release blog

QImage::loadFromData failing

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 3.0k 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.
  • R Offline
    R Offline
    Rory_1
    wrote on last edited by
    #1

    I'm building an image viewer app for raw files (extracting the embedded jpeg). I am sending a list of all the image absolute paths to a function that:

    • extracts the embedded jpeg into a QByteArray

    • creates a QImage via loadFromData

    • creates a Pixmap via from Image

    • adds the Pixmap to QPixmapCache

      void ImageView::loadImageCache(QFileInfoList &imageList)
      {
          QPixmapCache::clear();
          QPixmapCache::setCacheLimit(10240000);   //10GB
          for (int i=0; i < imageList.size(); ++i) {
              QFileInfo fileInfo = imageList.at(i);
              QString imageFullPath = fileInfo.absoluteFilePath();
              QPixmap pm;
              loadPixmap(imageFullPath, pm);
              QPixmapCache::insert(imageFullPath, pm);
           }
      }
      
      void ImageView::loadPixmap(QString &imageFullPath, QPixmap &pm)
      {
          QImage image;
          QFileInfo fileInfo(imageFullPath);
          QFile imFile(imageFullPath);
          imFile.open(QIODevice::ReadOnly);       
          imFile.seek(mdCache->getOffsetFullJPG(imageFullPath));
          QByteArray buf = imFile.read(mdCache->getLengthFullJPG(imageFullPath));
          bool imLoaded = image.loadFromData(buf, "JPEG");  // errors out after multiple calls
          pm = QPixmap::fromImage(image);
      }
      

    When working on a folder with 36MP NEF files bool imLoaded becomes false and stays that way for all repeated executions for the remaining files in the folder after 5-6 files have been processed. When I send a folder of smaller jpegs I may get 30 files before imLoaded becomes false. The accumulated memory for the Pixmaps is usually around 1.2 - 1.4 GB when the image.loadFromData statement returns false. The memory estimate is based on (width * height * depth)/8 bytes. The QByteArray buf continues to work, no matter how many files I process.

    I'm hoping I am doing something obviously wrong. If not, I'm hoping someone can give me some advice on how to proceed to solve this.

    Running Qt 5.5 Win 10

    Thanks in advance
    Rory

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gerd
      wrote on last edited by Gerd
      #2

      From QPixmap Documentation:
      Note that the pixel data in a pixmap is internal and is managed by the underlying window system.

      So, for Windows:

      • Pixmaps are stored as GDI-Objects
      • Memory for GDI-Objects is taken from windows paged kernel memory
      • paged kernel memory is limited by windows (on my 12GB win7 its around 1GB)

      If you really need to have 10GB of Images in memory you need

      • use QImage for storing data in memory
      • write your own Cache handling those Images
      • use Pixmap::fromImage(...) to display the Images

      Hope that helps
      gerd

      R 1 Reply Last reply
      1
      • G Gerd

        From QPixmap Documentation:
        Note that the pixel data in a pixmap is internal and is managed by the underlying window system.

        So, for Windows:

        • Pixmaps are stored as GDI-Objects
        • Memory for GDI-Objects is taken from windows paged kernel memory
        • paged kernel memory is limited by windows (on my 12GB win7 its around 1GB)

        If you really need to have 10GB of Images in memory you need

        • use QImage for storing data in memory
        • write your own Cache handling those Images
        • use Pixmap::fromImage(...) to display the Images

        Hope that helps
        gerd

        R Offline
        R Offline
        Rory_1
        wrote on last edited by
        #3

        @Gerd

        Thanks Gerd. I'll start researching how to do that. Very much appreciated!

        Rory

        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