Force Density Units on Read?
Posted: 2017-12-13T10:42:36-07:00
I am attempting to create a unit test around some dynamically generated images and wanted to ensure that images are being created at 300x300 dpi. In certain formats, such as png, they are being read back in metric, which fails my asserts. Is there a way to force it to dpi on read?
Some reproduce code:
I am running .Net 4.5.1 with nuget package Magick.NET-Q8-AnyCPU version 7.2.0.
Thanks
Some reproduce code:
Code: Select all
string lvFile = @"C:\Temp\test.png";
using (MagickImage lvImage = new MagickImage(new MagickColor(Color.Black), 2550, 3300))
{
lvImage.Settings.Format = MagickFormat.Png;
lvImage.Settings.Compression = Compression.Group4;
lvImage.Settings.Density = new Density(300, 300, DensityUnit.PixelsPerInch);
lvImage.Settings.Debug = true;
lvImage.Settings.Verbose = true;
lvImage.Density = new Density(300, 300, DensityUnit.PixelsPerInch);
lvImage.Write(lvFile);
}
using (MagickImage lvWrittenImage = new MagickImage(lvFile))
{
Trace.WriteLine(lvWrittenImage.Density); // Outputs 118.11x118.11 cm
}
Thanks