Memory of QRC files - too big
-
Hello everyone,
I have a deep question about memory management of PYQT with images, using the qrc files.
Let me give the details below.
The Raw images I want to add in my program in .jpg format : Total Size : 150 MB.
The QRC File : 1KB
The PY File after converting it with QRC. Total Size : 370 MB.
(I can compile it for a size reduction but I doesnt change anything for the last step which is my issue)
Memory My program takes once running, and not importing the image File : 99 MB
Memory My program takes once running, and importing the image File (py) : 1.08GB.Can anyone help me understand how and why do my images go from about 150mb to almost 1000 MB ?
Its just a program with buttons, a few frames, and images used as background in frames.Thanks
-
Hi,
How many images are you using ?
What size are they ?
One thing you might not have taken into account is that in order for an image to be shown, it must be uncompressed so for a 4k image with 8bit per channel:3840 x 2160 (image size) x 3 (number of channels)It's about 24MB per image. It can go update to 32 if using an image format that supports alpha.
-
@SGaist Thank you very much ! You are absolutely right. I took one random image I have, one that is 3000x7000 with 32 bit depth and apparently the uncompressed size is about 10 times the size shown in the system, which explains perfectly that gap I noticed between the compressed size and the memory it loads.
I suppose the only way to tackle this issue would be to reduce either the resolution or the bit depth of the image, prior to loading it into the qrc ?
-
B Brad1111 has marked this topic as solved on
-
@SGaist Thank you very much ! You are absolutely right. I took one random image I have, one that is 3000x7000 with 32 bit depth and apparently the uncompressed size is about 10 times the size shown in the system, which explains perfectly that gap I noticed between the compressed size and the memory it loads.
I suppose the only way to tackle this issue would be to reduce either the resolution or the bit depth of the image, prior to loading it into the qrc ?
@Brad1111 As usual, the sensible approach is to pack the largest size you might need but also to consider cache or even on-the-fly resizing prior to showing, where applicable of course.
Other way is to see if any of your images would benefit from being vector based (i.e. svg) than bitmap - it is very often possible for line art, icons and such. Small size, virtually unlimited and unaffected quality of resizing.