Setting Resolution / Density / DPI in images

Jan 5, 2014 at 1:37 PM
Hi,

I wonder how to change the density/resolution of an image using ImageMagick.net.

So far I tried:
Using img As MagickImage = New MagickImage()
    img.Read("LocalFilePath")
    img.Density.X = newdpi
    img.Density.Y = newdpi
    img.Write("ExportFilePath")
End Using
and
Using img As MagickImage = New MagickImage()
    img.Read("LocalFilePath")
    img.Density.Width = newdpi
    img.Density.Height = newdpi
    img.Write("ExportFilePath")
End Using
and
Using img As MagickImage = New MagickImage()
    img.Read("LocalFilePath")
    img.SetAttribute("resolution.x", "240")
    img.SetAttribute("resolution.x", "240")
    img.Write("ExportFilePath")
End Using
I also tried to set the values in the settings before reading:
                        Dim settings As MagickReadSettings
                        settings = New MagickReadSettings()
                        If expFile.colorspace = "rgb" Then settings.ColorSpace = ColorSpace.RGB
                        If expFile.colorspace = "cmyk" Then settings.ColorSpace = ColorSpace.CMYK
                        settings.Density = New MagickGeometry("240")
this seem to work for .eps and .png files at least.

Finally I did:
                              Dim geo As New MagickGeometry(expFile.dpi)
                              geo.Width = width
                              geo.Height = height
                              img.Transform(geo)
which doesn't work either.

I do store the images as jpg but other formats didn't work either.
Anybody has done such a transformation successfully ?

Thanks a lot
Herbert
Jan 6, 2014 at 7:00 AM
I think you posted your message on the wrong discussion board. The classes and methods you are using are from the Magick.NET library and not the ImageMagick.NET library. You can find the correct discussion board here: https://magick.codeplex.com/discussions.

Setting the DPI for an image really depends on the type of image you are reading and the type of image you are writing. Can you add an example image when you post your message on the other discussion board?