Jpeg compression


How can I set the compression level of the jpeg image I’m creating (in batch) with a c->SaveAs(“test.jpg”) instruction ?
The image seem to use a high compression level (root v5.14/00b)



Hi Damir,
You think it has a high compression level because the jpeg image looks a bit blury ? If so, that is not a problem of compression that’s intrinsic of the jpeg format. Jpeg format is good to render images or photos but not graphs with sharp transitions between colors, like, for instance, a black line on a white background. I would recommend you to use gif or png format instead.

Hi Olivier,

Yes, I know that the jpeg compression is lossy. But in all image manipulation programs you can set the level of intrinsic jpeg compression (the value of some frequency cut in the DFT algorithm I guess) and when this level is set to a high value, the image in jpeg does not have so much artefacts. I was just wondering if there is a way to control this.

In any case, if it is not possible, I’ll go to gif or png of course, even if I need to call an external program (convert) to make the conversion.



Hi Damir,
you can set image quality by … ageQuality

The possible values are:

   enum EImageQuality {
      kImgDefault = -1,
      kImgPoor    = 0,
      kImgFast    = 1,
      kImgGood    = 2,
      kImgBest    = 3

the same for image compression … ompression

the compression is in % units

Regards. Valeriy

Hi Valeriy,

Yes, I saw these methods, but they are not static and I don’t see how to enforce them when calling the “SaveAs” method of pad.
This must be something trivial…


Hi Damir,

$ root -b
root [0] .x tutorials/hsimple.C

TImageDump *imgdump = new TImageDump("hsimple.jpg");
TImage *img = imgdump->GetImage(); // get internal image
imgdump->Close(); // that will delete img

It’s probably usefull to add correspondent methods to TStyle class or
to provide possibility to set default values for image compression & quality
via TEnv (resource file).

Regards. Valeriy

Thanks, it works !
Though I wouldn’t have guessed it myself ! :slight_smile: