我在我的 ASP.NET 项目中使用 Magicknet 进行图像处理。如何获取和设置图像的图像分辨率? - 当我调整 300 像素/英寸图像的大小时,默认情况下显然会产生 72 像素/英寸图像,并且因为我保持相同的尺寸,所以我得到的图像质量非常低。所以我需要能够保持图像的ppi。
我还想补充一点,这可能会导致 magicknet 或 System.Drawing.Image,但我不是 100% 确定。
我使用的代码:
img.ModulusDepth = 10;
img.Compression = CompressionType.JPEGCompression;
img.Quality = 80;
string optimizedImage = System.Web.HttpContext.Current.Server.MapPath(".") + "\\temp\\" + Guid.NewGuid().ToString() + ".jpg";
img.Write(optimizedImage); // save optimized image as temp file
Magick.Term();
System.Drawing.Image tempimage = System.Drawing.Image.FromFile(optimizedImage); // load the optimized image into an image objec
根据我在这里读到的内容,默认为每英寸 72 像素。
谢谢
使用 MagickImage 类
Density
属性。
例如:
magickImageObj.Density = new Density(150, DensityUnit.PixelsPerInch);
Density 类还有一些其他构造函数重载可用。
图像 DPI 在网络上下文中是无关紧要的;这是所有浏览器和几乎所有打印机都忽略的元数据设置。
像素是您必须使用的单位; DPI 是一种漏洞抽象,每个库和 UI 的处理方式都不同。