IRONSOFTWAREHOME
Create and Cast Rectangle
using IronSoftware.Drawing;

// Cast between System.Drawing.Rectangle and IronSoftware.Drawing.Rectangle
System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(10, 10, 150, 150);
IronSoftware.Drawing.Rectangle ironRectangle = rectangle;

// Access Rectangle properties:
var x = ironRectangle.X;
var h = ironRectangle.Height;

// Cast between System.Drawing.RectangleF and IronSoftware.Drawing.RectangleF
System.Drawing.RectangleF rectangleF = new System.Drawing.RectangleF(8.8F, 10.2F, 100F, 125F);
IronSoftware.Drawing.RectangleF ironRectangleF = rectangleF;

// Access RectangleF properties:
var yFloat = ironRectangleF.Y;
var wFloat = ironRectangleF.Width;

NuGet Download
PM > Install-Package IronSoftware.System.Drawing
Create and Cast Rectangle

Create and Cast Rectangle

Rectangle and RectangleF are useful features provided by IronDrawing which can be used to crop any image file. Customers using rectangles from System.Drawing.Rectangle or System.Drawing.RectangleF can also cast them to IronSoftware.Drawing.Rectangle and IronSoftware.Drawing.RectangleF using the Cast method.

Create Rectangle & RectangleF

To create a Rectangle, users can instantiate a new Rectangle and provide the X and Y coordinates, as well as the width and height measurements of the Rectangle in pixels. For example:

Similarly, for the RectangleF class, a sample RectangleF object can be instantiated as follows:

Cast Rectangle & RectangleF

To cast an IronSoftware.Drawing.Rectangle from System.Drawing.Rectangle or an IronSoftware.Drawing.RectangleF from System.Drawing.RectangleF, you can use implicit conversion. Here's how you can do it:

In this example, we use implicit conversion to cast System.Drawing.Rectangle and System.Drawing.RectangleF to their IronSoftware.Drawing counterparts, making it straightforward to utilize these rectangles in IronDrawing's features.

View on GitHub

Ready to Get Started?

Nuget Downloads 19,926,787Version: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 IronPDF
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