Search Results for

    Show / Hide Table of Contents

    Class Size

    Stores an ordered pair of integers, which specify a height and width.

    Inheritance
    System.Object
    Size
    Implements
    System.IEquatable<Size>
    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)

    Initializes a new instance of the Size struct from the given 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)

    Contracts a Size by another 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)

    Converts a SizeF to a Size by performing a round operation on all the dimensions.

    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)

    Divides Size by an System.Int32 producing Size.

    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)

    Divides Size by a System.Single producing SizeF.

    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 right parameter; otherwise, false.

    Explicit(Size to Point)

    Converts the given Size into a 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)

    Creates a SizeF with the dimensions of the specified Size.

    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 right parameter; otherwise, false.

    Multiply(Size, Int32)

    Multiplies Size by an System.Int32 producing Size.

    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)

    Multiplies Size by a System.Single producing SizeF.

    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)

    Multiplies a Size by an System.Int32 producing 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)

    Multiplies Size by a System.Single producing SizeF.

    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.

    Implements

    System.IEquatable<>
    ☀
    ☾
    Downloads
    • Download with Nuget
    In This Article
    Back to top
    Install with Nuget
    IronDrawing_for_dotnet_log2o
    Blue key in circleGet started for FREE
    No credit card required
    Test in a live environment

    Test in production without watermarks.
    Works wherever you need it to.

    Fully-functional product

    Get 30 days of fully functional product.
    Have it up and running in minutes.

    24/5 technical support

    Full access to our support engineering team during your product trial

    Grey key in circleGet started for FREE
    The trial form was submitted successfully.
    Calendar in circleBook Free Live Demo
    No contact, no card details, no commitments Book a 30-minute, personal demo.
    Here's what to expect:

    A live demo of our product and its key features

    Get project specific feature recommendations

    All your questions are answered to make sure you have all the information you need. (No commitment whatsoever.)

    Grey key in circleBook Free Live Demo
    Your booking has been completed Check your e-mail for confirmation
    Support Team Member 6 related to The C# PDF Library Support Team Member 14 related to The C# PDF Library Support Team Member 4 related to The C# PDF Library Support Team Member 2 related to The C# PDF Library
    Online 24/5
    Need help? Our sales team would be glad to help you.
    Try the Enterprise Trial
    ironpdf_for_dotnet_log2o
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    bullet_checkedNo credit card or account creation required
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    Blue key in circleNo credit card or account creation required
    Green Check in orange circle
    The trial form was submitted successfully.
    badge_greencheck_in_yellowcircle
    Thank you for starting a trial

    Please check your email for the trial license key.

    If you don’t receive an email, please start a live chat or email support@ironsoftware.com

    Install with NuGet
    View Licensing
    • Logo Aetna
    • Logo NASA
    • Logo GE
    • Logo Porsche
    • Logo USDA
    • Logo Qatar
    Join Millions of Engineers who’ve tried IronDrawing