Skip to content

JpegBitmapEncoder default QualityLevel issue #11803

Description

@OlexandrPavliuk

Description

If to set QualityLevel of JpegBitmapEncoder to 75, the quality level of a generated image will be 90, not 75.

This happens because SetupFrame method checks if the value of the level is a default one (that is 75) and doesn't set ImageQuality property of the native encoder.

But, according to https://learn.microsoft.com/en-us/windows/win32/wic/jpeg-format-overview the default value of the quality in the native encoder is not 0.75, but 0.9.

Reproduction Steps

Execute the following code:

using var imageStreamSource = new FileStream("input.png", FileMode.Open, FileAccess.Read, FileShare.Read);

var decoder = BitmapDecoder.Create(imageStreamSource, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);

var frame = decoder.Frames[0];

var encoder = new JpegBitmapEncoder()
{
    QualityLevel = 75,
};

encoder.Frames.Add(decoder.Frames[0]);

using var fileStream = new FileStream("output.jpg", FileMode.Create);
encoder.Save(fileStream);

Expected behavior

Saved JPEG image has Quality Level 75

Actual behavior

Saved JPEG image has Quality Level 90

Regression?

No response

Known Workarounds

No response

Impact

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions