SixLabors/ImageSharp

Unable to save images with DPI changes

trinhpapa opened this issue · 6 comments

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

3.0.2

Other ImageSharp packages and versions

No

Environment (Operating system, version and so on)

Windows 11 and Linux

.NET Framework version

.NET 6

Description

I uploaded the image from the path and saved the image as Jpeg, but it automatic changed the DPI from 300 to 72. I tried changing the DPI to 32 but it still saved the image with 72 DPI default. It doesn't seem to work.

Steps to Reproduce

    using Image image = Image.Load(imagePath);
    var metaData = image.Metadata;
    var currentDPI = image.Metadata.HorizontalResolution;
    if (currentDPI < 300)
    {
        image.Metadata.VerticalResolution = 300;
        image.Metadata.HorizontalResolution = 300;
    }

    image.SaveAsJpeg("test.jpg", new JpegEncoder { Quality = 100 });

Images

code
Aaron_Jay_Young_4N4A3583

I don't actually understand your issue.

You talk about changing the DPI to values other than 300 but your code sample changes the DPI to 300?

I looked at the properties of the second image you uploaded and that also say that the DPI is 300?

image

I don't actually understand your issue.

You talk about changing the DPI to values other than 300 but your code sample changes the DPI to 300?

I looked at the properties of the second image you uploaded and that also say that the DPI is 300?
image

Yes, that's the example image I'm using for testing. When running that image and saving it to test.jpg, it is only 72dpi

test
This is image result, even though I tried changing or keeping the DPI the same, it was always 72 DPI

OK.

Please try to supply all the relevant information in one go, otherwise it's just noise.

Windows is reading the resolution from the EXIF metadata you need to change it in both places or remove the EXIF resolution metadata

image

Windows is reading the resolution from the EXIF metadata you need to change it in both places or remove the EXIF resolution metadata
image

Thanks for your information, it is useful information