Search Results for

    Show / Hide Table of Contents

    Class SizeF

    Stores an ordered pair of single precision floating points, which specify a height and width.

    Inheritance
    System.Object
    SizeF
    Implements
    System.IEquatable<SizeF>
    Namespace: IronSoftware.Drawing
    Assembly: IronSoftware.Drawing.Common.dll
    Syntax
    public sealed class SizeF : ValueType

    A precise, cross-library size record for floating-point dimensions, SizeF stores an ordered pair of float values representing Width and Height. It bridges IronDrawing with SkiaSharp (SKSize), System.Numerics (Vector2), and the rest of the .NET drawing ecosystem through a rich set of implicit and explicit conversions, so a size measured in one library passes cleanly into another without manual unpacking.

    Construct a SizeF from two floats, from a PointF, or by copying an existing SizeF. The static SizeF.Empty field provides a zero-initialized sentinel. Once created, Width and Height are mutable properties, and Deconstruct lets you unpack both values in a single tuple assignment. Equality is covered by both Equals(SizeF) and the == / != operators, making the struct safe to compare in conditional logic.

    **Arithmetic and geometry** are handled through named static methods and operator overloads:

    - Building and modifying: Add and the + operator combine two sizes; Subtract and the - operator reduce one. - Scaling: * scales a size by a scalar (both SizeF * float and float * SizeF); / divides by a scalar. - Transformation: Transform(SizeF, Matrix3x2) applies a 2-D affine matrix, useful for rotating or skewing a bounding box before passing it to a renderer.

    **Conversions** cover the most common cross-library handoffs. Implicit casts move a SizeF to SKSize and Vector2 without any explicit cast syntax. Explicit casts to PointF and Size are intentionally narrowing: PointF reinterprets the width and height as X and Y coordinates, while Size truncates the floats to integers.

    Because SizeF is a value type derived from ValueType, it allocates on the stack, copies by value, and carries no hidden heap cost. This makes it practical in tight loops that compute image tile dimensions, layout bounds, or canvas regions at high frequency.

    using IronSoftware.Drawing;
    using System.Numerics;
    
    SizeF original = new SizeF(120.5f, 80.25f);
    SizeF padding  = new SizeF(10f, 10f);
    SizeF padded   = SizeF.Add(original, padding);
    
    var (w, h) = padded;                      // Deconstruct
    SizeF scaled  = padded * 1.5f;
    Vector2 vec   = scaled;                   // implicit to Vector2
    Console.WriteLine(scaled.ToString());

    Explore more in the IronDrawing documentation, the IronDrawing code examples, and the Cast to AnyBitmap example.

    Constructors

    SizeF(PointF)

    Initializes a new instance of the SizeF struct from the given PointF.

    Declaration
    public SizeF(PointF point)
    Parameters
    Type Name Description
    PointF point

    The point.

    SizeF(SizeF)

    Initializes a new instance of the SizeF struct.

    Declaration
    public SizeF(SizeF size)
    Parameters
    Type Name Description
    SizeF size

    The size.

    SizeF(Single, Single)

    Initializes a new instance of the SizeF struct.

    Declaration
    public SizeF(float width, float height)
    Parameters
    Type Name Description
    System.Single width

    The width of the size.

    System.Single height

    The height of the size.

    Fields

    Empty

    Represents a SizeF that has Width and Height values set to zero.

    Declaration
    public static readonly SizeF Empty
    Field Value
    Type Description
    SizeF

    Properties

    Height

    Gets or sets the height of this SizeF.

    Declaration
    public float Height { get; set; }
    Property Value
    Type Description
    System.Single

    Width

    Gets or sets the width of this SizeF.

    Declaration
    public float Width { get; set; }
    Property Value
    Type Description
    System.Single

    Methods

    Add(SizeF, SizeF)

    Performs vector addition of two SizeF objects.

    Declaration
    public static SizeF Add(SizeF left, SizeF right)
    Parameters
    Type Name Description
    SizeF left

    The size on the left hand of the operand.

    SizeF right

    The size on the right hand of the operand.

    Returns
    Type Description
    SizeF

    The SizeF.

    Deconstruct(out Single, out Single)

    Deconstructs this size into two floats.

    Declaration
    public void Deconstruct(out float width, out float height)
    Parameters
    Type Name Description
    System.Single width

    The out value for the width.

    System.Single height

    The out value for the height.

    Equals(SizeF)

    Declaration
    public bool Equals(SizeF other)
    Parameters
    Type Name Description
    SizeF 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(SizeF, SizeF)

    Contracts a SizeF by another SizeF.

    Declaration
    public static SizeF Subtract(SizeF left, SizeF right)
    Parameters
    Type Name Description
    SizeF left

    The size on the left hand of the operand.

    SizeF right

    The size on the right hand of the operand.

    Returns
    Type Description
    SizeF

    The SizeF.

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String

    Transform(SizeF, Matrix3x2)

    Transforms a size by the given matrix.

    Declaration
    public static SizeF Transform(SizeF size, Matrix3x2 matrix)
    Parameters
    Type Name Description
    SizeF size

    The source size.

    System.Numerics.Matrix3x2 matrix

    The transformation matrix.

    Returns
    Type Description
    SizeF

    A transformed size.

    Operators

    Addition(SizeF, SizeF)

    Computes the sum of adding two sizes.

    Declaration
    public static SizeF operator +(SizeF left, SizeF right)
    Parameters
    Type Name Description
    SizeF left

    The size on the left hand of the operand.

    SizeF right

    The size on the right hand of the operand.

    Returns
    Type Description
    SizeF

    The SizeF.

    Division(SizeF, Single)

    Divides SizeF by a System.Single producing SizeF.

    Declaration
    public static SizeF operator /(SizeF left, float right)
    Parameters
    Type Name Description
    SizeF left

    Dividend of type SizeF.

    System.Single right

    Divisor of type System.Int32.

    Returns
    Type Description
    SizeF

    Result of type SizeF.

    Equality(SizeF, SizeF)

    Compares two SizeF objects for equality.

    Declaration
    public static bool operator ==(SizeF left, SizeF right)
    Parameters
    Type Name Description
    SizeF left

    The size on the left hand of the operand.

    SizeF right

    The size on the right hand of the operand.

    Returns
    Type Description
    System.Boolean

    True if the current left is equal to the right parameter; otherwise, false.

    Explicit(SizeF to PointF)

    Converts the given SizeF into a PointF.

    Declaration
    public static explicit operator PointF(SizeF size)
    Parameters
    Type Name Description
    SizeF size

    The size.

    Returns
    Type Description
    PointF

    Explicit(SizeF to Size)

    Creates a Size with the dimensions of the specified SizeF by truncating each of the dimensions.

    Declaration
    public static explicit operator Size(SizeF size)
    Parameters
    Type Name Description
    SizeF size

    The size.

    Returns
    Type Description
    Size

    The Size.

    Implicit(SizeF to SizeF)

    Convert to a Microsoft.Maui.Graphics.SizeF type.

    Declaration
    public static implicit operator SizeF(SizeF v)
    Parameters
    Type Name Description
    SizeF v
    Returns
    Type Description
    Microsoft.Maui.Graphics.SizeF

    Implicit(SizeF to SizeF)

    Convert to a SixLabors.ImageSharp.SizeF type.

    Declaration
    public static implicit operator SizeF(SizeF v)
    Parameters
    Type Name Description
    SizeF v
    Returns
    Type Description
    SixLabors.ImageSharp.SizeF

    Implicit(SizeF to SKSize)

    Convert to a SkiaSharp.SKSize type.

    Declaration
    public static implicit operator SKSize(SizeF v)
    Parameters
    Type Name Description
    SizeF v
    Returns
    Type Description
    SkiaSharp.SKSize

    Implicit(SizeF to SizeF)

    Convert to a System.Drawing.Size type.

    Declaration
    public static implicit operator SizeF(SizeF v)
    Parameters
    Type Name Description
    SizeF v
    Returns
    Type Description
    System.Drawing.SizeF

    Implicit(SizeF to Vector2)

    Creates a System.Numerics.Vector2 with the coordinates of the specified PointF.

    Declaration
    public static implicit operator Vector2(SizeF point)
    Parameters
    Type Name Description
    SizeF point

    The point.

    Returns
    Type Description
    System.Numerics.Vector2

    The System.Numerics.Vector2.

    Implicit(SizeF to SizeF)

    Convert a Microsoft.Maui.Graphics.SizeF type to a SizeF type.

    Declaration
    public static implicit operator SizeF(SizeF v)
    Parameters
    Type Name Description
    Microsoft.Maui.Graphics.SizeF v
    Returns
    Type Description
    SizeF

    Implicit(SizeF to SizeF)

    Convert a System.Drawing.SizeF type to a SizeF type.

    Declaration
    public static implicit operator SizeF(SizeF v)
    Parameters
    Type Name Description
    SixLabors.ImageSharp.SizeF v
    Returns
    Type Description
    SizeF

    Implicit(SKSize to SizeF)

    Convert a SkiaSharp.SKSize type to a SizeF type.

    Declaration
    public static implicit operator SizeF(SKSize v)
    Parameters
    Type Name Description
    SkiaSharp.SKSize v
    Returns
    Type Description
    SizeF

    Implicit(SizeF to SizeF)

    Convert a System.Drawing.SizeF type to a SizeF type.

    Declaration
    public static implicit operator SizeF(SizeF v)
    Parameters
    Type Name Description
    System.Drawing.SizeF v
    Returns
    Type Description
    SizeF

    Inequality(SizeF, SizeF)

    Compares two SizeF objects for inequality.

    Declaration
    public static bool operator !=(SizeF left, SizeF right)
    Parameters
    Type Name Description
    SizeF left

    The size on the left hand of the operand.

    SizeF right

    The size on the right hand of the operand.

    Returns
    Type Description
    System.Boolean

    True if the current left is unequal to the right parameter; otherwise, false.

    Multiply(SizeF, Single)

    Multiplies SizeF by a System.Single producing SizeF.

    Declaration
    public static SizeF operator *(SizeF left, float right)
    Parameters
    Type Name Description
    SizeF left

    Multiplicand of type SizeF.

    System.Single right

    Multiplier of type System.Single.

    Returns
    Type Description
    SizeF

    Product of type SizeF.

    Multiply(Single, SizeF)

    Multiplies SizeF by a System.Single producing SizeF.

    Declaration
    public static SizeF operator *(float left, SizeF right)
    Parameters
    Type Name Description
    System.Single left

    Multiplier of type System.Single.

    SizeF right

    Multiplicand of type SizeF.

    Returns
    Type Description
    SizeF

    Product of type SizeF.

    Subtraction(SizeF, SizeF)

    Computes the difference left by subtracting one size from another.

    Declaration
    public static SizeF operator -(SizeF left, SizeF right)
    Parameters
    Type Name Description
    SizeF left

    The size on the left hand of the operand.

    SizeF right

    The size on the right hand of the operand.

    Returns
    Type Description
    SizeF

    The SizeF.

    Implements

    System.IEquatable<>
    ☀
    ☾
    Downloads
    • Download with Nuget
    In This Article
    Back to top
    Install with Nuget