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);
Imports IronSoftware.Drawing
Imports System
' Instantiate a Rectangle (Default measurement unit is pixels)
Private pxCropRect As New Rectangle(15, 25, 150, 175) ' (X, Y, Width, Height)
' Convert and print a Rectangle measurement in millimeters
Private mmCropRect As Rectangle = pxCropRect.ConvertTo(MeasurementUnits.Millimeters, 20)
Console.WriteLine(mmCropRect.X)
' Instantiate a RectangleF in millimeters
Dim pxCropRectFloat As New IronSoftware.Drawing.RectangleF(10F, 25F, 100F, 175F, MeasurementUnits.Millimeters) ' (X, Y, Width, Height, Units)
' Convert and print a RectangleF measurement in pixels
Dim mmCropRectFloat As IronSoftware.Drawing.RectangleF = pxCropRectFloat.ConvertTo(MeasurementUnits.Pixels, 30)
Console.WriteLine(mmCropRectFloat.Y)
Install-Package IronSoftware.System.Drawing
Convert Measurement Units
IronDrawing provides option for users who wants to change the measurement unit used in Rectangle or RectangleF from pixels (px) to milimeters (mm) or vice versa. Default measurement unit used in Rectangle and RectangleF is pixels (px).
After a new Rectangle with measurements specified has been instantiated, call the conversion method to the Rectangle. For example .ConvertTo(MeasurementUnits.Millimeters, 20). This will convert the measurements of the Rectangle to millimeters based on the DPI set by users. This same approach can also be applied for RectangleF class.
Related Docs Links
1510001
Now that you’ve downloaded IronPDF
Want to deploy IronPDF to a live project for FREE?
Not ready to buy?
Want to deploy IronDrawing to a live project for FREE?
What’s included?
Test in production without watermarks
30 days fully functional product
24/5 technical support during trial
Get your free 30-day Trial Key instantly.
Thank you. If you'd like to speak to our licensing team: