Class Size
Stores an ordered pair of integers, which specify a height and width.
Inheritance
Implements
Namespace: IronSoftware.Drawing
Assembly: IronSoftware.Drawing.Common.dll
Syntax
public sealed class Size : ValueType
An ordered pair of integers, Width and Height, is what Size stores, making it the standard dimensional record for pixel measurements across IronDrawing. Anywhere a bitmap dimension, canvas bound, or layout rectangle needs to be expressed as discrete integer units, Size is the value that carries it. Because Size is a ValueType, it copies by value and requires no heap allocation, which keeps hot paths that create many dimensions allocation-free.
Construction is flexible. Pass a single int to set both axes to the same value, supply separate width and height integers, copy an existing Size, or convert from a Point. The static field Size.Empty gives a zero-by-zero sentinel without allocating. When a floating-point dimension is available, Size.Truncate(SizeF) converts it to integer coordinates by truncating toward zero, and Size.Transform(Size, Matrix3x2) applies an affine matrix and returns a SizeF for sub-pixel precision.
**Building and modifying:** Add and Subtract combine two sizes component-wise, mirrored by the + and - operators. Scalar multiplication and division are available through * and / with both int and float right-hand operands, the float variants returning SizeF to preserve fractional results. Deconstruct lets you unpack Width and Height directly in a tuple assignment.
**Conversions:** Size converts implicitly to SizeF and to SKSizeI, and accepts implicit conversions from SKSizeI and from several platform Size types, so it slots into SkiaSharp pipelines and cross-platform graphics APIs without explicit casts. An explicit cast to Point is available when the dimension needs to be treated as a coordinate.
**Equality and formatting:** Equals(Size), Equals(object), GetHashCode, the == and != operators, and ToString round out the value-type contract.
using IronSoftware.Drawing;
// Construct, combine, and deconstruct a Size
var canvas = new Size(1920, 1080);
var border = new Size(20);
Size padded = Size.Add(canvas, border);
var (w, h) = padded;
Console.WriteLine($"{w} x {h}"); // 1940 x 1100
// Scale down by half (integer result)
Size half = padded / 2;
// Implicit widening to SizeF for sub-pixel work
SizeF precise = half;Explore the IronDrawing get-started guide for installation, the color and image primitives docs for how Size relates to Rectangle and Point, the AnyBitmap how-to for bitmap dimension workflows, and the coordinate types example for practical conversion patterns.
Constructors
Size(Point)
Declaration
public Size(Point point)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | point | The point. |
Size(Size)
Initializes a new instance of the Size struct.
Declaration
public Size(Size size)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | size | The size. |
Size(Int32)
Initializes a new instance of the Size struct.
Declaration
public Size(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | value | The width and height of the size. |
Size(Int32, Int32)
Initializes a new instance of the Size struct.
Declaration
public Size(int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | width | The width of the size. |
| System.Int32 | height | The height of the size. |
Fields
Empty
Represents a Size that has Width and Height values set to zero.
Declaration
public static readonly Size Empty
Field Value
| Type | Description |
|---|---|
| Size |
Properties
Height
Gets or sets the height of this Size.
Declaration
public int Height { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Width
Gets or sets the width of this Size.
Declaration
public int Width { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Methods
Add(Size, Size)
Performs vector addition of two Size objects.
Declaration
public static Size Add(Size left, Size right)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | left | The size on the left hand of the operand. |
| Size | right | The size on the right hand of the operand. |
Returns
| Type | Description |
|---|---|
| Size | The Size. |
Deconstruct(out Int32, out Int32)
Deconstructs this size into two integers.
Declaration
public void Deconstruct(out int width, out int height)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | width | The out value for the width. |
| System.Int32 | height | The out value for the height. |
Equals(Size)
Declaration
public bool Equals(Size other)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | other |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Equals(Object)
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj |
Returns
| Type | Description |
|---|---|
| System.Boolean |
GetHashCode()
Calculate a hash code.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 |
Subtract(Size, Size)
Declaration
public static Size Subtract(Size left, Size right)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | left | The size on the left hand of the operand. |
| Size | right | The size on the right hand of the operand. |
Returns
| Type | Description |
|---|---|
| Size | The Size. |
ToString()
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String |
Transform(Size, Matrix3x2)
Transforms a size by the given matrix.
Declaration
public static SizeF Transform(Size size, Matrix3x2 matrix)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | size | The source size. |
| System.Numerics.Matrix3x2 | matrix | The transformation matrix. |
Returns
| Type | Description |
|---|---|
| SizeF | A transformed size. |
Truncate(SizeF)
Declaration
public static Size Truncate(SizeF size)
Parameters
| Type | Name | Description |
|---|---|---|
| SizeF | size | The size. |
Returns
| Type | Description |
|---|---|
| Size | The Size. |
Operators
Addition(Size, Size)
Computes the sum of adding two sizes.
Declaration
public static Size operator +(Size left, Size right)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | left | The size on the left hand of the operand. |
| Size | right | The size on the right hand of the operand. |
Returns
| Type | Description |
|---|---|
| Size | The Size. |
Division(Size, Int32)
Declaration
public static Size operator /(Size left, int right)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | left | Dividend of type Size. |
| System.Int32 | right | Divisor of type System.Int32. |
Returns
| Type | Description |
|---|---|
| Size | Result of type Size. |
Division(Size, Single)
Declaration
public static SizeF operator /(Size left, float right)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | left | Dividend of type Size. |
| System.Single | right | Divisor of type System.Int32. |
Returns
| Type | Description |
|---|---|
| SizeF | Result of type SizeF. |
Equality(Size, Size)
Compares two Size objects for equality.
Declaration
public static bool operator ==(Size left, Size right)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | left | The Size on the left side of the operand. |
| Size | right | The Size on the right side of the operand. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the current left is equal to the |
Explicit(Size to Point)
Declaration
public static explicit operator Point(Size size)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | size | The size. |
Returns
| Type | Description |
|---|---|
| Point |
Implicit(Size to SizeF)
Declaration
public static implicit operator SizeF(Size size)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | size | The point. |
Returns
| Type | Description |
|---|---|
| SizeF |
Implicit(Size to Size)
Convert to a Microsoft.Maui.Graphics.Size type.
Declaration
public static implicit operator Size(Size v)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | v |
Returns
| Type | Description |
|---|---|
| Microsoft.Maui.Graphics.Size |
Implicit(Size to Size)
Convert to a SixLabors.ImageSharp.Size type.
Declaration
public static implicit operator Size(Size v)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | v |
Returns
| Type | Description |
|---|---|
| SixLabors.ImageSharp.Size |
Implicit(Size to SKSizeI)
Convert to a SkiaSharp.SKSizeI type.
Declaration
public static implicit operator SKSizeI(Size v)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | v |
Returns
| Type | Description |
|---|---|
| SkiaSharp.SKSizeI |
Implicit(Size to Size)
Convert to a System.Drawing.Size type.
Declaration
public static implicit operator Size(Size v)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | v |
Returns
| Type | Description |
|---|---|
| System.Drawing.Size |
Implicit(Size to Size)
Convert a Microsoft.Maui.Graphics.Size type to a Size type.
Declaration
public static implicit operator Size(Size v)
Parameters
| Type | Name | Description |
|---|---|---|
| Microsoft.Maui.Graphics.Size | v |
Returns
| Type | Description |
|---|---|
| Size |
Implicit(Size to Size)
Convert a SixLabors.ImageSharp.Size type to a Size type.
Declaration
public static implicit operator Size(Size v)
Parameters
| Type | Name | Description |
|---|---|---|
| SixLabors.ImageSharp.Size | v |
Returns
| Type | Description |
|---|---|
| Size |
Implicit(SKSizeI to Size)
Convert a SkiaSharp.SKSizeI type to a Size type.
Declaration
public static implicit operator Size(SKSizeI v)
Parameters
| Type | Name | Description |
|---|---|---|
| SkiaSharp.SKSizeI | v |
Returns
| Type | Description |
|---|---|
| Size |
Implicit(Size to Size)
Convert a System.Drawing.Size type to a Size type.
Declaration
public static implicit operator Size(Size v)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Drawing.Size | v |
Returns
| Type | Description |
|---|---|
| Size |
Inequality(Size, Size)
Compares two Size objects for inequality.
Declaration
public static bool operator !=(Size left, Size right)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | left | The Size on the left side of the operand. |
| Size | right | The Size on the right side of the operand. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the current left is unequal to the |
Multiply(Size, Int32)
Declaration
public static Size operator *(Size left, int right)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | left | Multiplicand of type Size. |
| System.Int32 | right | Multiplier of type System.Int32. |
Returns
| Type | Description |
|---|---|
| Size | Product of type Size. |
Multiply(Size, Single)
Declaration
public static SizeF operator *(Size left, float right)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | left | Multiplicand of type Size. |
| System.Single | right | Multiplier of type System.Single. |
Returns
| Type | Description |
|---|---|
| SizeF | Product of type SizeF. |
Multiply(Int32, Size)
Declaration
public static Size operator *(int left, Size right)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | left | Multiplier of type System.Int32. |
| Size | right | Multiplicand of type Size. |
Returns
| Type | Description |
|---|---|
| Size | Product of type Size. |
Multiply(Single, Size)
Declaration
public static SizeF operator *(float left, Size right)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | left | Multiplier of type System.Single. |
| Size | right | Multiplicand of type Size. |
Returns
| Type | Description |
|---|---|
| SizeF | Product of type SizeF. |
Subtraction(Size, Size)
Computes the difference left by subtracting one size from another.
Declaration
public static Size operator -(Size left, Size right)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | left | The size on the left hand of the operand. |
| Size | right | The size on the right hand of the operand. |
Returns
| Type | Description |
|---|---|
| Size | The Size. |