IRONSOFTWAREHOME
Convert Measurement Units
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
Convert Measurement Units

Convert Measurement Units

IronDrawing provides an option for users who want to change the measurement unit used in Rectangle or RectangleF from pixels (px) to millimeters (mm) or vice versa. The default measurement unit used in Rectangle and RectangleF is pixels (px).

After a new Rectangle with measurements specified has been instantiated, you can call the conversion method on the Rectangle. For example, use ConvertTo(MeasurementUnits.Millimeters, 20). This will convert the measurements of the Rectangle to millimeters based on the DPI set by the user. This same approach can also be applied to the RectangleF class.

View on GitHub

Ready to Get Started?

Nuget Downloads 20,033,450Version:2025.3just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required