I have a large image that I have to save with image.save(fichier). How could I possibly display a progressbar of the saving state?
This may be a trivial question but I really don't how to do this as it's a one-line command...
You probably can't using the built in image save. You could estimate the save time (know size of image, guess mb/s), and put up a progress bar and just use a timer to update it.
Or you can have a progress bar that just runs quickly to the end and restarts to show some activity but not the actual progress.
edit: if you really must have a progress you could 'save' the image data in memory and then write the memory to disk a block at a time updating the progress.
QImage image;
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "PNG"); // writes image into buffer in PNG format
Then write the buffer to disk
You can run QImage::save() in another thread, while the main thread shows the progressbar, updating its progress value every second with expected_size/current_size. You can get current size with QFile::size()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With