簡體   English   中英

c#:使用MagickImage更改圖像DPI並調整圖像大小

[英]c#: change image DPI using MagickImage and resize the image

我正在使用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

我如何以編程方式做到這一點。 謝謝

您可以執行以下操作:

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


            }
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM