Png images
-
Hi,
We have a Qt application for ARM-base board with a lot of small .png images (button backgrounds, icons,...).
At startup, we get this message : "QImage: out of memory, returning null image". However, the application continues to start up and there seem no more problem after that.
Moreover, most images are larger that they appear on screen, so they need to be rescaled at runtime by Qt.
I suspect the number of images and the rescaling to be the cause of the problem. But, I'm not sure, because I don't know how png's are handled by Qt applications.
We put all our png images in our project's .qrc file. I guess, they all end up, still in png format, in the executable. But what happens when launching the application ? Is Qt extracting all images at once or just those it needs at that time ? How are the images extracted : in compressed png format or in un-compressed full size (in terms of memory) format ? When it has to rescale an image, I guess it first has to uncompress the image before it can rescale it. So, at a certain time, the full size image (in terms of memory) will be present in memory. Correct ? Once scaled, will the original image be removed from memory ?Thanks in advance for help !
Filip
-
I'm not sure what's the problem, can you paste some code?
-
Hi Chuck,
I don't know if there's really a problem... There's the message at startup, indicating that we are possibly running low in memory, but that's it...
In fact, I'm just curious in how Qt is handling png's because :- it might not be the best solution to have lots of png's in an application with respect to memory consumption.
- it might not be a good idea to let the application scale the images at runtime.
Filip
-
What is the final size of your executable when you do use the resource system? How much RAM does your target device have?
Do you get the same problem if you do not compile the images into your application using the resource system?
-
[quote author="filip" date="1305896713"]Hi Chuck,
I don't know if there's really a problem... There's the message at startup, indicating that we are possibly running low in memory, but that's it...
In fact, I'm just curious in how Qt is handling png's because :- it might not be the best solution to have lots of png's in an application with respect to memory consumption.
- it might not be a good idea to let the application scale the images at runtime.
Filip[/quote]
Yes, actually when you use Qt resource system(as you know .qrc) in your project, and the rcc(resource compiler)will turn it to cpp, and it's compiled in with your application. As ZapB asked, maybe it's too large for ARM-based board using.It's depend on your image size.
But, if you want to load the image at run time, you can don't use qrc, or load qrc resource dynamically instead of compile it in.
-
The final size of the executable is 1198462 bytes.
Target has 64 Mb of RAM.
Not yet tested when not compiled in to application.
Number of png's in qrc file : 170! -
If you are targeting a particular device it is pointless to rescale the images at runtime over and over again. Much better idea to rescale them once offline and use the rescaled images directly.
-
[quote author="ZapB" date="1305897728"]If you are targeting a particular device it is pointless to rescale the images at runtime over and over again. Much better idea to rescale them once offline and use the rescaled images directly.[/quote]
Agree. Different device, different resolution.
-
Just to be sure my reasoning is right :
One of the images is 25Kb in size. If I open that image, the size is 3289x1385 pixels. So, if we have to rescale that, the app has to load the original image in memory meaning consuming 3289x1385x3 = 13,66Mb of RAM (if I assume 24 bits per pixel). Right ? -
Yes except it is more likely 4 bytes per pixel since it could well be using RGBA pixel format. What is your screen resolution on your device? I doubt it is anywhere near that image size is it?
-
The screen resolution of the target is 800x480 !
Well, it's clear that this way of working is not a good choice at all... it looks like the application will need some rework...
Resizing the images once to their correct size will certainly resolve the "out of memory" problem...Thanks !
-
The app should not need much reworking if it is already using the larger images. You just need to spend a little time in your favourite image editor rescaling the png's to more suitable sizes. Another bonus is that yoru app will load faster (since it will be smaller) and it will also display the images faster since there will be no slow software scaling to be performed.
-
Stupid remark of me...! Of course, app should normally not change one byte... only scale images.
-
No worries - it's Friday afternoon. My brain has already departed for the weekend ;-)
-
- Imaging scaling is very expensive and memory constrained in low memory devices like handhelds.
- Why don't you use svg instead of png. They scale to the target resolution and work like a charm in low memory targets.
- If you still prefer to use png files, please scale it yourself and provide an image cache that resides on the disk rather than on RAM. If you downscale try doing a "cheat scale":http://labs.qt.nokia.com/2009/01/26/creating-thumbnail-preview/