Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to reduce the time cost of QImage::save() ?
I am using QImage to draw my model and I want to store all images in my computer.But I found that compared with drawing job itself , QImage::save() costs more time. In my example, drawing a 4K pic uses 20ms, but when you save it to your hard disk it costs 300ms. Is there any way to reduce the time cost of QImage::save() ?
@MartinChan3 Just to understand your use case: why are 300ms a problem? Do you store each rendered frame as a picture?
JonB last edited by
Well, there is no reason saving it as a file should compare to the time taken to render it.
How big is the image file, how fast is your "hard disk"?
Try saving to device
/dev/null(Linux), how does that compare? That should tell you whether it's processing time or disk time.
I note that https://stackoverflow.com/questions/51377481/qimage-save-is-too-slow reports similar, but that user reported 20 seconds while you are reporting 300 milliseconds! It didn't get a solution, but see the comments, FWIW try compiling your app for release with optimization flags to see if that affects it?
@jsulm I am working on accelerating the saving job due to my project need to draw a sequence of frames and store them in my computer ( for 3d printing ).My job need about 2000 pictures and I want to accelerate the process ,so I do some research on time count and I found the save() costs the most time. That's why I care about the time cost.
Use a lower compression level and a format which is easy to compress.
I tried optimized compile and it didn't have a obvious effect...
You can move the save out into an own thread but this should be your last resort esp. since you have to make sure that you don't go out of memory in your case.
JonB last edited by
I would also check out using a RAMDISk to write on if you have memory for it.
Write speed is around 6000 MB/s so it's much faster than an HDD.
But if file is only 100 kb, then it seems like as mentioned by the others, its indeed the compression
that takes time. As even a HHD can write 100 kb fast :)