[SOLVED]Does Qt provide a way to determine the size of an PNG image file before save it?
-
I'm currently working with QImage to create a PNG file with the highest compression available (quality=0).
That process may spend some time, depending of the dimensions of the image.
I'm saving it in a separete thread, and on the main thread i want to have a progressbar showing the progress of the save task, I know that i can use QFile::size() to determine the number of generated bytes, but i need to know how much bytes the image will have and with that information calculate the progress of the save task.
How can I do that?
-
In my experience, I've found that using a progress bar to show every step in the process may end by making it slower than it should be; it is better to update the progress bar every n steps (where n may be the result of TotalSteps/AnyNumberYouWant) so you don't overload Qt with output functions. With this in mind and as matter of efficiency, users may not want to know how many bytes of the total size are done, instead, if you're using loops to process your QImage, you may update your progress bar every n iterations and it will provide the same result to users.
I hope I've helped you somehow :)
-
Thanks @BlastDV! But to use loops I need to split the save task into peaces, how can I do that?
-
You may just create a "global" QImage and assign chunks to every thread. So every one of them copies its processed data to the corresponding chunk of the original QImage and after you joined all of your threads, you simply save that one.
For example, every thread takes a row from the original QImage and then return the processed data to the global output one.
But thinking of PNGs, I don't remember how you manage compression with that extension, I assume you know it, but the proccess may be similar since you need to remove repeated colors or things like that, depending on the compression method you're using. The idea I'm giving to you may be the most basic one, but It may work for an initial approach.
-
Thanks again @BlastDV! I will do that!