QImage: out of memory, returning null image
-
Hello,
I am making a view that displays a map, made up of square tiles. Each tile is an image has 1070 x 1070 pixels. The view only loads the tiles that are visible in the view.
When my app starts only one tile is visible. But nothing is displayed because of the error in the subject of this post.
I converted the image to a TIFF with no compression from a PNG, and it's size is 3.33 Megabytes. Does not seem to be very big by todays starndards. I am on a windows machine with windows 10 and have 16GB Memory.What can I do ?
Thanks,
Regards -
When my app starts only one tile is visible.
Only one visible, but how many tiles does the program actually try to load? Is it caching everything?
What can I do?
You could share a self-contained example program that demonstrates the issue. It matters what the source data is and how exactly you try to load it. It also matters what Qt version. This, for example, works fine for me:
#include <QCoreApplication> #include <QImage> #include <QDebug> int main(int argc, char **argv) { QCoreApplication app(argc, argv); QImage image("test.png"); qDebug() << image; return 0; }
for an input file:
$ convert -size 1070x1070 -depth 8 plasma:fractal test.png $ identify test.png test.png PNG 1070x1070 1070x1070+0+0 8-bit sRGB 1.91768MiB 0.000u 0:00.000
outputs:
QImage(QSize(1070, 1070),format=QImage::Format_RGB32,depth=32,devicePixelRatio=1,bytesPerLine=4280,sizeInBytes=4579600)
(Linux, 64-bit, gcc, Qt 5.12.8)
-
Hello,
I slimmed down my code, and commented the following in it :
QTransform flipVertical; flipVertical.scale(1*metadata->scale, -1*metadata->scale); pixmapAt = pixmapAt->transformed(flipVertical);
And the error disappeared and my images are being loaded.
So what I need to do now is preprocess them to make the flip and then use them in the code.
Anyway, this is strange, the transform takes up that much memory ?Thanks,
Regards -
So you get the reported error when transforming a QPixmap/QImage rather than loading an QImage.
What is the value of
metadata->scale
? If this is, for example, 10 then your image grows quite a lot. Worse, ifmetadata->scale
is uninitialised then the transformed image might grow to unmanageable size.QPixmap is limited to 16384x16384. The maximum QImage size is governed by the storage required, which cannot exceed MAX_INT and must be allocatable as a single block. If you are transforming a QPixmap then it uses an internal QImage IIRC.
-
Hi and thanks for the swift answer,
I am using the value 2000 in the scale so 1078x2000 = 2156000 which is greater than 16384. That's it, isn't it ?
Regards
-
@Daniel-Santos
Unless I misunderstand, @ChrisW67 only said it must not be greater than16384 * 16384
. Both your numbers are comfortably less.EDIT I did indeed misunderstand what @Daniel-Santos is doing :)
-
@JonB I think you misunderstood @Daniel-Santos
his metadata->scale is 2000, therefore any image bigger than 8x8 will run out of memory ;)