Results 1 to 4 of 4

Thread: Most Memory-Efficient Way to Add Images to QGraphicsScene?

  1. #1
    Join Date
    May 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Most Memory-Efficient Way to Add Images to QGraphicsScene?

    I have a series of six JPEG images that I'd like to display on the same QGraphicsScene. Each grayscale JPEG is approximately 4000x3400 pixels and just under 700 KB in file size.

    I'm wondering about the most memory-efficient way to place these six JPEGs as items in a single graphics scene. I've looked into adding them as QGraphicsPixmapItems using the following code:

    Qt Code:
    1. QPixmap ncpPix(ncpPath);
    2. pixItem ->setPixmap(ncpPix);
    3. scene->addItem(ncpItem);
    To copy to clipboard, switch view to plain text mode 

    The problem is that the setPixmap() operation seems to consume more than 60 MB of memory for each new pixmap item I add to the scene. For six images, that's not really going to cut it. I've done some basic profiling of my application and the memory overhead of the graphics scene and graphics view is minimal - the problem is with setPixmap. What other options do I have for placing those JPEGs in the scene? Am I doing something terribly wrong? Are there straightforward steps I can take to decrease the memory footprint of displaying multiple JPEGs as items in a graphics scene?

    NOTE: I'm using the stock Qt JPEG plugin to deal with the JPEG images.
    Last edited by datek2517; 28th June 2011 at 04:49.

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Most Memory-Efficient Way to Add Images to QGraphicsScene?

    Your images may only be 700k on disk, but when uncompressed they contain roughly 13 megapixels. Each pixel takes up some space, depending on what sort of image your pixmap is set to receive.

    The default is to assume a full color image with an alpha channel, so you wind up claiming roughly 55 megabytes per image. Setting the optional constructor flag 'format' to 'Qt::MonoOnly' will force the image to grayscale, which will only take about 13 megabytes.

    That's the best you can do without reducing the image size/resolution. It's impossible to say whether this is an option without knowing more.

  3. #3
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Most Memory-Efficient Way to Add Images to QGraphicsScene?

    If you describe what you are trying to achieve with your pixmaps in the scene, we might help with your app's memory consumption and/or performance.

  4. #4
    Join Date
    May 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Most Memory-Efficient Way to Add Images to QGraphicsScene?

    Thanks a lot for your help. I'm loading these in as image items so that users can look at the images side-by-side with synchronized zooming and panning capabilities. I have a single QGraphicsScene that contains all of the pixmap items and a series of QGraphicsViews centered on particular images.

    I thought the graphics view framework made the most sense since we will also want to add layers of overlays, icons, and text over the images in the future. Also, though it's not needed for this particular application, I wanted to provide for the future ability to layer the images on top of one another within the same view and allow a user to move them around and hide certain images. So it's for more than just displaying the images.

    Quote Originally Posted by SixDegrees View Post
    Your images may only be 700k on disk, but when uncompressed they contain roughly 13 megapixels. Each pixel takes up some space, depending on what sort of image your pixmap is set to receive.

    The default is to assume a full color image with an alpha channel, so you wind up claiming roughly 55 megabytes per image. Setting the optional constructor flag 'format' to 'Qt::MonoOnly' will force the image to grayscale, which will only take about 13 megabytes.

    That's the best you can do without reducing the image size/resolution. It's impossible to say whether this is an option without knowing more.
    Thanks for the insights. I tried using the MonoOnly optimization flag but didn't notice any difference with memory usage:

    Qt Code:
    1. QPixmap ncpPix(imgPath, 0, Qt::MonoOnly);
    2. pixItem->setPixmap(imgPix);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 28th April 2012, 09:58
  2. most efficient way to get a QPixmap from a QImage
    By caduel in forum Qt Programming
    Replies: 3
    Last Post: 11th June 2011, 13:00
  3. how to load images from phone memory
    By trupti in forum Qt Programming
    Replies: 11
    Last Post: 7th January 2011, 12:24
  4. QGraphicsScene - memory consumption
    By mateuszzz88 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 29th November 2010, 21:39
  5. QGraphicsScene - order of images drawn
    By bjh in forum Qt Programming
    Replies: 2
    Last Post: 29th November 2007, 16:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.