PDA

View Full Version : QImage size limitation



JovianGhost
23rd March 2010, 00:23
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?

aamer4yu
23rd March 2010, 05:13
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 ;)

JohannesMunk
23rd March 2010, 11:17
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

JovianGhost
24th March 2010, 12:01
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.