how can i change picture dpi from 96 dpi to 300 dpi i c#
What I have tried:
private void button2_Click(object sender, EventArgs e)
{
var filename = @"--input--image--";
var targetfile = @"--output-image--";
using (var image = Image.FromFile(filename))
{
// changing to 96 DPI
var resolution = new byte[8] { 0, 0, 96, 0, 0, 0, 1, 0 };
if (image.PropertyIdList.Contains(282))
{
var xResolution = image.GetPropertyItem(300);
xResolution.Value = resolution;
image.SetPropertyItem(xResolution);
}
if (image.PropertyIdList.Contains(283))
{
var yResolution = image.GetPropertyItem(300);
yResolution.Value = resolution;
image.SetPropertyItem(yResolution);
}
image.Save(targetfile, image.RawFormat);
}
}
but this is not working