How to set JPEG compression level?
-
-
I'm trying to save a JPEG(*.jpg) file using QImageWriter but the compression level does not seem to respond to any values I set using setCompression method.
Is it possible to this without using any third-party libraries?
Any ideas are much appreciated.@amahta said:
Hi I wonder if it's related to this ?
http://asmaloney.com/2011/11/code/qimagewriter-and-writing-jpegs/ -
I'm trying to save a JPEG(*.jpg) file using QImageWriter but the compression level does not seem to respond to any values I set using setCompression method.
Is it possible to this without using any third-party libraries?
Any ideas are much appreciated.@amahta
Hello it depends on what the qjpeg plugin supports. Unfortunately, I can't seem to be able to find more detailed information about that plugin. Still, JPEG I believe adjusts the compression based on the quality parameter, so maybe try with setting that, instead of the compression property?Kind regards.
-
@amahta said:
Hi I wonder if it's related to this ?
http://asmaloney.com/2011/11/code/qimagewriter-and-writing-jpegs/ -
@amahta
Hello it depends on what the qjpeg plugin supports. Unfortunately, I can't seem to be able to find more detailed information about that plugin. Still, JPEG I believe adjusts the compression based on the quality parameter, so maybe try with setting that, instead of the compression property?Kind regards.
@kshegunov said:
@amahta
Hello it depends on what the qjpeg plugin supports. Unfortunately, I can't seem to be able to find more detailed information about that plugin. Still, JPEG I believe adjusts the compression based on the quality parameter, so maybe try with setting that, instead of the compression property?Kind regards.
Wow, thank you @kshegunov ! How did I miss that :)
It works when I use setQualityHere is a part of setQuality documentation exactly answering my problem:
Sets the quality setting of the image format to quality.
Some image formats, in particular lossy ones, entail a tradeoff between a) visual quality of the resulting image, and b) encoding execution time and compression level. This function sets the level of that tradeoff for image formats that support it. For other formats, this value is ignored.
The value range of quality depends on the image format. For example, the "jpeg" format supports a quality range from 0 (low visual quality, high compression) to 100 (high visual quality, low compression).Thanks again.
-
@kshegunov said:
@amahta
Hello it depends on what the qjpeg plugin supports. Unfortunately, I can't seem to be able to find more detailed information about that plugin. Still, JPEG I believe adjusts the compression based on the quality parameter, so maybe try with setting that, instead of the compression property?Kind regards.
Wow, thank you @kshegunov ! How did I miss that :)
It works when I use setQualityHere is a part of setQuality documentation exactly answering my problem:
Sets the quality setting of the image format to quality.
Some image formats, in particular lossy ones, entail a tradeoff between a) visual quality of the resulting image, and b) encoding execution time and compression level. This function sets the level of that tradeoff for image formats that support it. For other formats, this value is ignored.
The value range of quality depends on the image format. For example, the "jpeg" format supports a quality range from 0 (low visual quality, high compression) to 100 (high visual quality, low compression).Thanks again.