Results 1 to 4 of 4

Thread: QImage size limitation

  1. #1
    Join Date
    Mar 2010
    Posts
    55
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default QImage size limitation

    I'm trying to create a QImage, which I will edit with setPixel and convert to a QPixmap. The problem is QImage's constructor seems to fail when I specify large dimensions. In my case, I need a QImage which is around 40,000 x 40,000. If I try to construct using new and check the object, it's null.

    Is this a limitation of the class, or just something related to the available system resources? More importantly, is there any way to override this?

    If not, I need another way to draw to a very large background device context which I can then render to the screen.

    I should mention that if I lower the size to 20,000 x 20,000 it's ok, and I notice the amount of memory usage is very little (a few megeabytes) so why one that's 4 times the size be such a problem?
    Last edited by JovianGhost; 23rd March 2010 at 02:19.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage size limitation

    Do the calculations yourself
    a 20000 x 20000 image with 32 bits format will require 20000 x 20000 x 32 bits
    = 20000 x 20000 x 4 bytes
    = 20000 x 19.5 x 4 MB
    How many GB is that ??? Does your pc has that memory ?
    Now do the calculations for 40000 x 40000

  3. #3
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage size limitation

    Pixels:
    20k x 20k = 400M
    40k x 40k = 1600M
    Bytes: * 4B
    1600MB
    4800MB
    I think your statement 20kx20k is just a few megabytes is based on some false readings. Maybe the memory isn't allocated immediately?

    Why do you need such a large background? Have you looked into the QGraphicsView-Framework? There you can comfortably fill your background and have individually buffered items..

    Joh

  4. #4
    Join Date
    Mar 2010
    Posts
    55
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QImage size limitation

    Thanks for your replies.

    I realize that requires a lot of memory, but then I wonder why I can safely create a 20k x 20k with very little memory usage?

    I need to draw a sparse scene with lots of pixels (millions) and I've found that using the GraphicsView framework takes up far too much memory, so I'm going to have to implement this more low-level.
    I guess the better way to do this would be to draw directly to the device context in the paintEvent function.

Similar Threads

  1. Creating QImage of specified size from qpic
    By suneel1310 in forum Qt Programming
    Replies: 4
    Last Post: 31st March 2009, 10:53
  2. QPoint Limitation
    By archanasubodh in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2008, 10:22
  3. Font size calculation when painting in a QImage
    By Ishark in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2007, 22:22
  4. Limitation when adding more than 256 items to a model
    By darkadept in forum Qt Programming
    Replies: 5
    Last Post: 25th May 2006, 15:26

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.