We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Reading out jpeg quality seems to be wrong

Hi Aspose Support!

I’d like to open a jpeg file and determine the compression ratio (quality), but it seems no matter what image I open, I always get the same value (75)

Here is a small code how I try to read out the quality value ->

byte[] LoadImageBytes(string samplefile)
{
    return File.ReadAllBytes(samplefile);
}
MemoryStream LoadMemoryStreamImage(string samplefile)
{
    return new MemoryStream(LoadImageBytes(samplefile));
}
string samplefile = "<path_to_jpg>";
Aspose.Imaging.FileFormats.Jpeg.JpegImage jpgImage = null;
using (var memStream = LoadMemoryStreamImage(samplefile))
{
    jpgImage = new Aspose.Imaging.FileFormats.Jpeg.JpegImage(memStream);
}
Console.WriteLine(samplefile + " -> quality: " + jpgImage.JpegOptions.Quality);

Am I missing something here?

Thank you for your support!
Laszlo

@lorbanops It is impossible to determine the compression ratio of a saved Jpeg image. It can be only guessed with some precision, but it won’t be true value.
The JpegOptions.Quality property specifies a value for saving loaded image. The value of 75 is the default one.

Thank you @Alexey.Karpenko for your quick response!

I wouldn’t say that it is impossible to determine, but it is true that it can only be guessed, however my problem is that when I load a jpeg image into a Aspose.Imaging.FileFormats.Jpeg.JpegImage object, and I query the quality value from THAT object, I get this default value instead of a guessed value.

The API documentation says: JpegOptioins.Quality - Gets or sets image quality.

It does not get any real (guessed) value, this property can only be used to SET the quality before saving.

@lorbanops Thank you for pointing out confusing part in our API. We will investigate possible solution options and notify you.