IRONSOFTWAREHOME
转换计量单位
using IronSoftware.Drawing;
using System;

// Instantiate a Rectangle (Default measurement unit is pixels)
Rectangle pxCropRect = new Rectangle(15, 25, 150, 175); // (X, Y, Width, Height)

// Convert and print a Rectangle measurement in millimeters
Rectangle mmCropRect = pxCropRect.ConvertTo(MeasurementUnits.Millimeters, 20);
Console.WriteLine(mmCropRect.X);

// Instantiate a RectangleF in millimeters
IronSoftware.Drawing.RectangleF pxCropRectFloat = new IronSoftware.Drawing.RectangleF(10F, 25F, 100F, 175F, MeasurementUnits.Millimeters); // (X, Y, Width, Height, Units)

// Convert and print a RectangleF measurement in pixels
IronSoftware.Drawing.RectangleF mmCropRectFloat = pxCropRectFloat.ConvertTo(MeasurementUnits.Pixels, 30);
Console.WriteLine(mmCropRectFloat.Y);


NuGet Download
PM > Install-Package IronSoftware.System.Drawing
转换计量单位

转换计量单位

IronDrawing为希望将RectangleF中使用的测量单位从像素(px)更改为毫米(mm)或反之的用户提供了一个选项。 在RectangleF中使用的默认测量单位是像素(px)。

在实例化了一个具有指定测量单位的新Rectangle上调用转换方法。 例如,使用ConvertTo(MeasurementUnits.Millimeters, 20)。 这将根据用户设置的DPI将Rectangle的测量值转换为毫米。 这种方法也可以应用于RectangleF类。

在 GitHub 上查看

准备开始了吗?

Nuget Downloads 19,846,219版本:2025.3刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

OR
bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户