1

What is the fastest way to save a qimage ?

I have an image with 2448 x 2050 resolution and it takes around 5 seconds to save a single image in my computer.

I save images into png extension and set the compression level to 1. I've read the same topic as my question but I still don't understand how to set the PNG filter to none. Can someone elaborate?

For what it's worth, I'm using pyqt. Can anyone suggest me to improve the speed please? Thank you in advance

Community
  • 1
  • 1
Denny Dharmawan
  • 167
  • 3
  • 13
  • usually i would suggest using `bool QImage::save ( const QString & fileName, const char * format = 0, int quality = -1 ) const` but i am shure you tried that allready – Zaiborg Nov 20 '14 at 08:47
  • shouldn't the quality be 1? Yes, i've tried that. It doesn't give any significant improvement – Denny Dharmawan Nov 20 '14 at 11:12
  • the signature ist just the default of qt4.8 where `-1` is default, `0` should be low quality up to `100` for high quality – Zaiborg Nov 20 '14 at 13:22
  • 1
    @DennyDharmawan. Why do you want to "set the PNG filter to none"? What image format do you want? And why are you setting the quality to 1? That is the *highest* level of compression, and so, unsurprisingly, it will be the *slowest* to create. Setting the quality to 100 will be the fastest. – ekhumoro Nov 20 '14 at 16:59
  • @ekhumoro, Please refer to the link attached and marked as (same topic) on my original post, a guy had similar question like me and he discovered that it would be faster if we set the PNG filter to none. I thought that 1 is the fastest, isn't it? – Denny Dharmawan Nov 21 '14 at 08:44
  • @DennyDharmawan, the comment in the question you linked is referring to using the libpng library in C++ to save the image. It is not a Qt function. As ekhumoro said, a quality value of 100 gives you the least compression/greatest speed. This is quoted from the docs in the answer you linked. – user3419537 Nov 21 '14 at 10:35
  • 1
    @DennyDharmawan. No, setting the quality to 1 is the slowest, which you can easily verify for yourself by just trying it. The reason why I asked the other questions, is that you don't make it clear in your question what image format you actually want. You only asked "What is the fastest way to save a qimage?". The various image formats Qt supports probaly vary in their performance (I haven't personally tested this hunch, though). If PNG is not a requirement, then maybe you should try some of the other formats to see if you get better performance. – ekhumoro Nov 21 '14 at 18:13

1 Answers1

0

Whilst the answer is implicit in various comments above, it is not explicitly stated in a standalone answer. The answer is based on the Qt documentation on QImage::save https://doc.qt.io/qt-5/qimage.html#save :

The quality factor must be in the range 0 to 100 or -1. Specify 0 to obtain small compressed files, 100 for large uncompressed files, and -1 (the default) to use the default settings.

The above quote can be re-expressed in the following table which indicates that you need to set quality to 100 to achieve the fastest conversion at the expense of producing the largest file size:

quality file size speed
0 smallest slowest
100 largest fastest

i.e.

    image.save("fast-but-uncompressed.png", "png", 100);
Stephen Quan
  • 21,481
  • 4
  • 88
  • 75