【问题标题】:c#: change image DPI using MagickImage and resize the imagec#: 使用 MagickImage 更改图像 DPI 并调整图像大小
【发布时间】:2026-02-22 08:25:01
【问题描述】:

我正在使用 MagickImage 更改图像的 Dpi,但它不起作用

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");
        }

或者如果这不起作用

有没有办法像 Photoshop 那样调整图像大小

example the image with 300 dPi have a w1200xh788 size

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

我怎样才能以编程方式做到这一点。谢谢

【问题讨论】:

  • 是的,我已经读过了。但是我怎么知道 72 dpi 的图像大小?
  • 您可以右键单击图像并转到属性,选择详细信息选项卡,您可以看到该图像的大小。
  • 先生,我正在以编程方式进行操作,例如 300 dPi 的图像具有 w1200xh788 大小并使用 Photoshop。我将 dpi 更改为 72,它创建了一个 w288xh189
  • @Chirag 你能发表你的评论作为答案吗?谢谢你。以便我将我的问题标记为已解决谢谢

标签: c# image image-resizing magicknet


【解决方案1】:

你可以这样做:

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);


            }
        }
    }

【讨论】: