简体   繁体   中英

c#: change image DPI using MagickImage and resize the image

i am using MagickImage to change Dpi of an image but it doesn't work

MagickNET.SetGhostscriptDirectory(System.IO.Directory.GetCurrentDirectory());
        MagickReadSettings settings = new MagickReadSettings();
        settings.Density = new Density(72, 72);
        using (MagickImage image = new MagickImage(@"C:\Users\User\AppData\Local\Temp\Chapter 4\Figure 4-1.tif", settings))
        {
            image.Write(@"C:\Users\User\AppData\Local\Temp\Chapter 4\Figure 4-1.jpg");
        }

or if this doesn't work

is there a way to resize the image like what the photoshop did

example the image with 300 dPi have a w1200xh788 size

and using photoshop. i changed the dpi to 72 and it creates a w288xh189

how can i programmatically do this. thank you

You can do as following :

using System;

    namespace ImageDPI
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                int Aw, Ah, Rw, Rh, Adpi, Rdpi;

                Aw = 1200;
                Ah = 788;

                Adpi = 300;
                Rdpi = 72;

                Rw= (Aw * Rdpi) / Adpi;
                Rh= (Ah * Rdpi) / Adpi;

                Console.WriteLine(Rw);
                Console.WriteLine(Rh);


            }
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM