How to change resolution (DPI) of an image?

ulduz114 picture ulduz114 · Dec 13, 2010 · Viewed 140.4k times · Source

I have a JPEG picture with a DPI of 72. I want to change 72 dpi to 300 dpi.

How could I change resolution of JPEG pictures using C#?

Answer

Simon Mourier picture Simon Mourier · Dec 13, 2010

You have to copy the bits over a new image with the target resolution, like this:

    using (Bitmap bitmap = (Bitmap)Image.FromFile("file.jpg"))
    {
        using (Bitmap newBitmap = new Bitmap(bitmap))
        {
            newBitmap.SetResolution(300, 300);
            newBitmap.Save("file300.jpg", ImageFormat.Jpeg);
        }
    }