Maybe I should add a new overload for the Resample method:
The only issue with this is that the input image should have the correct dimensions. This means that you will need to do the calculation yourself anyways. You will need to do this because you either want to crop or extent the image to the required dimensions. So maybe this is a better solution:
Your thoughts?
using (MagickImage image = new MagickImage("yourfile.jpg")) { Density density = new Density(300, DensityUnit.PixelsPerInch); double width = 2.13; // inchesdouble height = 2.5; // inches image.Resample(density, width, height); /* * And this would do: * int imageWidth = 2.13 * 300; // 639 * int imageHeight = 2.5 * 300; // 750 * image.Density = 300; * image.Resize(imageWidth, imageHeight); */ }
int dpi = 300; double width = 2.13; // inchesdouble height = 2.5; // inches Density density = new Density(dpi, DensityUnit.PixelsPerInch); MagickGeometry geometry = density.ToGeometry(width, height); Console.WriteLine(geometry.ToString()); // 639x750// And you could use the geometry to resize the image.