Class RectangleF
A universally compatible RectangleF for .NET 7, .NET 6, .NET 5, and .NET Core. As well as compatibility with Windows, NanoServer, IIS, macOS, Mobile, Xamarin, iOS, Android, Google Compute, Azure, AWS, and Linux.
Works nicely with popular Image RectangleF such as System.Drawing.RectangleF, SkiaSharp.SKRect, SixLabors.ImageSharp.RectangleF, Microsoft.Maui.Graphics.Rect.
Implicit casting means that using this class to input and output RectangleF from public APIs gives full compatibility to all RectangleF type fully supported by Microsoft.
Inheritance
Namespace: IronSoftware.Drawing
Assembly: IronSoftware.Drawing.Common.dll
Syntax
public class RectangleF : Object
Cross-platform rectangle geometry in floating-point coordinates becomes portable across every major .NET imaging library when you use RectangleF from IronSoftware.Drawing. A single value of this type flows without explicit casting into System.Drawing.RectangleF, SkiaSharp.SKRect, SixLabors.ImageSharp.RectangleF, and Microsoft.Maui.Graphics.Rect, so a method that accepts or returns IronSoftware.Drawing.RectangleF works transparently with whichever graphics stack the caller already uses.
Construct a rectangle with new RectangleF(float x, float y, float width, float height, MeasurementUnits units) or with a PointF and SizeF pair. The Units property records whether the values are pixels, inches, or another MeasurementUnits member, and ConvertTo(MeasurementUnits toUnits, int dpi) reprojects the rectangle into a different unit system at a given DPI, defaulting to 96. The derived edges Left, Top, Right, and Bottom are computed from X, Y, Width, and Height, so you never have to calculate bounds manually. Contains(int x, int y) tests whether a pixel coordinate falls inside the rectangle, which is useful for hit-testing regions in image-processing pipelines.
The implicit operator set is the key design feature. Assigning an IronSoftware.Drawing.RectangleF to a SkiaSharp.SKRect variable, or passing a Microsoft.Maui.Graphics.Rect where an IronSoftware.Drawing.RectangleF is expected, requires no cast syntax. The same implicit conversions work in both directions for System.Drawing.RectangleF, SkiaSharp.SKRect, Microsoft.Maui.Graphics.RectF, and Microsoft.Maui.Graphics.Rect. This makes RectangleF a practical neutral currency type for library APIs that need to stay decoupled from any one imaging dependency.
Runtime targets include .NET 7, .NET 6, .NET 5, .NET Core, and .NET Standard, and the type runs on Windows, macOS, Linux, NanoServer, iOS, Android, and cloud environments such as Azure, AWS, and Google Compute.
using IronSoftware.Drawing;
using SkiaSharp;
// Construct with explicit units
RectangleF region = new RectangleF(10f, 20f, 200f, 150f, MeasurementUnits.Pixels);
// Derived edges
Console.WriteLine($"Right={region.Right}, Bottom={region.Bottom}");
// Hit-test a coordinate
bool hit = region.Contains(50, 80);
// Convert to inches at 300 DPI
RectangleF inches = region.ConvertTo(MeasurementUnits.Inches, 300);
// Implicit cast to SkiaSharp - no explicit conversion needed
SKRect skRect = region;Explore further at the IronDrawing getting-started guide, the drawing docs overview, the cross-platform compatibility how-to, and the rectangle usage examples.
Constructors
RectangleF()
Construct a new RectangleF.
Declaration
public RectangleF()
See Also
RectangleF(PointF, SizeF, MeasurementUnits)
Initializes a new instance of the RectangleF struct.
Declaration
public RectangleF(PointF point, SizeF size, MeasurementUnits units)
Parameters
| Type | Name | Description |
|---|---|---|
| PointF | point | The Point which specifies the rectangles point in a two-dimensional plane. |
| SizeF | size | The IronSoftware.Drawing.RectangleF.Size which specifies the rectangles height and width. The measurement unit of this RectangleF |
| MeasurementUnits | units |
See Also
RectangleF(Single, Single, Single, Single, MeasurementUnits)
Construct a new RectangleF.
Declaration
public RectangleF(float x, float y, float width, float height, MeasurementUnits units)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | x | The x-coordinate of the upper-left corner of this RectangleF |
| System.Single | y | The y-coordinate of the upper-left corner of this RectangleF |
| System.Single | width | The width of this RectangleF |
| System.Single | height | The height of this RectangleF |
| MeasurementUnits | units | The measurement unit of this RectangleF |
See Also
Properties
Bottom
Gets the y-coordinate of the bottom edge of this RectangleF.
Declaration
public float Bottom { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Height
The height of this RectangleF. The default is 0
Declaration
public float Height { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Left
Gets the x-coordinate of the left edge of this RectangleF.
Declaration
public float Left { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Right
Gets the x-coordinate of the right edge of this RectangleF.
Declaration
public float Right { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Top
Gets the y-coordinate of the top edge of this RectangleF.
Declaration
public float Top { get; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Units
The measurement unit of this RectangleF. The default is Pixels
Declaration
public MeasurementUnits Units { get; set; }
Property Value
| Type | Description |
|---|---|
| MeasurementUnits |
Width
The width of this RectangleF. The default is 0
Declaration
public float Width { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
X
The x-coordinate of the upper-left corner of this RectangleF. The default is 0
Declaration
public float X { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Y
The y-coordinate of the upper-left corner of this RectangleF. The default is 0
Declaration
public float Y { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Single |
Methods
Contains(Int32, Int32)
Determines if the specified point is contained within the rectangular region defined by this RectangleF.
Declaration
public bool Contains(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | The x-coordinate of the given point. |
| System.Int32 | y | The y-coordinate of the given point. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
ConvertTo(MeasurementUnits, Int32)
Convert this RectangleF to the specified units of measurement using the specified DPI
Declaration
public RectangleF ConvertTo(MeasurementUnits toUnits, int dpi = 96)
Parameters
| Type | Name | Description |
|---|---|---|
| MeasurementUnits | toUnits | Unit of measurement |
| System.Int32 | dpi | DPI (Dots per inch) for conversion |
Returns
| Type | Description |
|---|---|
| RectangleF | A new RectangleF which uses the desired units of measurement |
Exceptions
| Type | Condition |
|---|---|
| System.NotImplementedException | Conversion not implemented |
Operators
Implicit(RectangleF to Rect)
Implicitly casts to Microsoft.Maui.Graphics.Rect objects from RectangleF.
When your .NET Class methods use RectangleF as parameters and return types, you now automatically support Microsoft.Maui.Graphics.Rect as well.
Declaration
public static implicit operator Rect(RectangleF RectangleF)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | RectangleF | RectangleF is explicitly cast to a Microsoft.Maui.Graphics.Rect. |
Returns
| Type | Description |
|---|---|
| Microsoft.Maui.Graphics.Rect |
Implicit(RectangleF to RectF)
Implicitly casts to Microsoft.Maui.Graphics.RectF objects from RectangleF.
When your .NET Class methods use RectangleF as parameters and return types, you now automatically support Microsoft.Maui.Graphics.RectF as well.
Declaration
public static implicit operator RectF(RectangleF RectangleF)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | RectangleF | RectangleF is explicitly cast to a Microsoft.Maui.Graphics.RectF. |
Returns
| Type | Description |
|---|---|
| Microsoft.Maui.Graphics.RectF |
Implicit(RectangleF to RectangleF)
Implicitly casts to SixLabors.ImageSharp.RectangleF objects from RectangleF.
When your .NET Class methods use RectangleF as parameters and return types, you now automatically support SixLabors.ImageSharp.RectangleF as well.
Declaration
public static implicit operator RectangleF(RectangleF RectangleF)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | RectangleF | RectangleF is explicitly cast to a SixLabors.ImageSharp.RectangleF. |
Returns
| Type | Description |
|---|---|
| SixLabors.ImageSharp.RectangleF |
Implicit(RectangleF to SKRect)
Implicitly casts to SkiaSharp.SKRect objects from RectangleF.
When your .NET Class methods use RectangleF as parameters and return types, you now automatically support SkiaSharp.SKRect as well.
Declaration
public static implicit operator SKRect(RectangleF RectangleF)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | RectangleF | RectangleF is explicitly cast to a SkiaSharp.SKRect. |
Returns
| Type | Description |
|---|---|
| SkiaSharp.SKRect |
Implicit(RectangleF to RectangleF)
Implicitly casts to System.Drawing.RectangleF objects from RectangleF.
When your .NET Class methods use RectangleF as parameters and return types, you now automatically support RectangleF as well.
Declaration
public static implicit operator RectangleF(RectangleF RectangleF)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | RectangleF | RectangleF is explicitly cast to a System.Drawing.RectangleF. |
Returns
| Type | Description |
|---|---|
| System.Drawing.RectangleF |
Implicit(Rect to RectangleF)
Implicitly casts Microsoft.Maui.Graphics.Rect objects to RectangleF.
When your .NET Class methods use RectangleF as parameters and return types, you now automatically support Microsoft.Maui.Graphics.Rect as well.
Declaration
public static implicit operator RectangleF(Rect RectangleF)
Parameters
| Type | Name | Description |
|---|---|---|
| Microsoft.Maui.Graphics.Rect | RectangleF | Microsoft.Maui.Graphics.Rect will automatically be casted to RectangleF. |
Returns
| Type | Description |
|---|---|
| RectangleF |
Implicit(RectF to RectangleF)
Implicitly casts Microsoft.Maui.Graphics.RectF objects to RectangleF.
When your .NET Class methods use RectangleF as parameters and return types, you now automatically support Microsoft.Maui.Graphics.RectF as well.
Declaration
public static implicit operator RectangleF(RectF RectangleF)
Parameters
| Type | Name | Description |
|---|---|---|
| Microsoft.Maui.Graphics.RectF | RectangleF | Microsoft.Maui.Graphics.RectF will automatically be casted to RectangleF. |
Returns
| Type | Description |
|---|---|
| RectangleF |
Implicit(RectangleF to RectangleF)
Implicitly casts SixLabors.ImageSharp.RectangleF objects to RectangleF.
When your .NET Class methods use RectangleF as parameters and return types, you now automatically support SixLabors.ImageSharp.RectangleF as well.
Declaration
public static implicit operator RectangleF(RectangleF RectangleF)
Parameters
| Type | Name | Description |
|---|---|---|
| SixLabors.ImageSharp.RectangleF | RectangleF | SixLabors.ImageSharp.RectangleF will automatically be casted to RectangleF. |
Returns
| Type | Description |
|---|---|
| RectangleF |
Implicit(SKRect to RectangleF)
Implicitly casts SkiaSharp.SKRect objects to RectangleF.
When your .NET Class methods use RectangleF as parameters and return types, you now automatically support SkiaSharp.SKRect as well.
Declaration
public static implicit operator RectangleF(SKRect sKRect)
Parameters
| Type | Name | Description |
|---|---|---|
| SkiaSharp.SKRect | sKRect | SkiaSharp.SKRect will automatically be casted to RectangleF. |
Returns
| Type | Description |
|---|---|
| RectangleF |
Implicit(RectangleF to RectangleF)
Implicitly casts System.Drawing.RectangleF objects to RectangleF.
When your .NET Class methods use RectangleF as parameters and return types, you now automatically support RectangleF as well.
Declaration
public static implicit operator RectangleF(RectangleF RectangleF)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Drawing.RectangleF | RectangleF | System.Drawing.RectangleF will automatically be casted to RectangleF. |
Returns
| Type | Description |
|---|---|
| RectangleF |