Table of Contents

Struct PixelSize

Namespace
Avalonia
Assembly
Avalonia.Base.dll

Represents a size in device pixels.

public readonly struct PixelSize : IEquatable<PixelSize>
Implements
Inherited Members

Constructors

PixelSize(int, int)

Initializes a new instance of the PixelSize structure.

public PixelSize(int width, int height)

Parameters

width int

The width.

height int

The height.

Fields

Empty

A size representing zero

public static readonly PixelSize Empty

Field Value

PixelSize

Properties

AspectRatio

Gets the aspect ratio of the size.

public double AspectRatio { get; }

Property Value

double

Height

Gets the height.

public int Height { get; }

Property Value

int

Width

Gets the width.

public int Width { get; }

Property Value

int

Methods

Equals(PixelSize)

Returns a boolean indicating whether the size is equal to the other given size.

public bool Equals(PixelSize other)

Parameters

other PixelSize

The other size to test equality against.

Returns

bool

True if this size is equal to other; False otherwise.

Equals(object?)

Checks for equality between a size and an object.

public override bool Equals(object? obj)

Parameters

obj object

The object.

Returns

bool

True if obj is a size that equals the current size.

FromSize(Size, Vector)

Converts a Size to device pixels using the specified scaling factor.

public static PixelSize FromSize(Size size, Vector scale)

Parameters

size Size

The size.

scale Vector

The scaling factor.

Returns

PixelSize

The device-independent size.

FromSize(Size, double)

Converts a Size to device pixels using the specified scaling factor.

public static PixelSize FromSize(Size size, double scale)

Parameters

size Size

The size.

scale double

The scaling factor.

Returns

PixelSize

The device-independent size.

FromSizeWithDpi(Size, Vector)

Converts a Size to device pixels using the specified dots per inch (DPI).

public static PixelSize FromSizeWithDpi(Size size, Vector dpi)

Parameters

size Size

The size.

dpi Vector

The dots per inch.

Returns

PixelSize

The device-independent size.

FromSizeWithDpi(Size, double)

Converts a Size to device pixels using the specified dots per inch (DPI).

public static PixelSize FromSizeWithDpi(Size size, double dpi)

Parameters

size Size

The size.

dpi double

The dots per inch.

Returns

PixelSize

The device-independent size.

GetHashCode()

Returns a hash code for a PixelSize.

public override int GetHashCode()

Returns

int

The hash code.

Parse(string)

Parses a PixelSize string.

public static PixelSize Parse(string s)

Parameters

s string

The string.

Returns

PixelSize

The PixelSize.

Exceptions

FormatException

ToSize(Vector)

Converts the PixelSize to a device-independent Size using the specified scaling factor.

public Size ToSize(Vector scale)

Parameters

scale Vector

The scaling factor.

Returns

Size

The device-independent size.

ToSize(double)

Converts the PixelSize to a device-independent Size using the specified scaling factor.

public Size ToSize(double scale)

Parameters

scale double

The scaling factor.

Returns

Size

The device-independent size.

ToSizeWithDpi(Vector)

Converts the PixelSize to a device-independent Size using the specified dots per inch (DPI).

public Size ToSizeWithDpi(Vector dpi)

Parameters

dpi Vector

The dots per inch.

Returns

Size

The device-independent size.

ToSizeWithDpi(double)

Converts the PixelSize to a device-independent Size using the specified dots per inch (DPI).

public Size ToSizeWithDpi(double dpi)

Parameters

dpi double

The dots per inch.

Returns

Size

The device-independent size.

ToString()

Returns the string representation of the size.

public override string ToString()

Returns

string

The string representation of the size.

TryParse(string?, out PixelSize)

Try parsing source as PixelSize.

public static bool TryParse(string? source, out PixelSize result)

Parameters

source string

The string to parse.

result PixelSize

The result of parsing. if source is not valid result is Empty

Returns

bool

true if source is valid PixelSize, otherwise false.

WithHeight(int)

Returns a new PixelSize with the same width and the specified height.

public PixelSize WithHeight(int height)

Parameters

height int

The height.

Returns

PixelSize

The new PixelSize.

WithWidth(int)

Returns a new PixelSize with the same height and the specified width.

public PixelSize WithWidth(int width)

Parameters

width int

The width.

Returns

PixelSize

The new PixelSize.

Operators

operator ==(PixelSize, PixelSize)

Checks for equality between two PixelSizes.

public static bool operator ==(PixelSize left, PixelSize right)

Parameters

left PixelSize

The first size.

right PixelSize

The second size.

Returns

bool

True if the sizes are equal; otherwise false.

operator !=(PixelSize, PixelSize)

Checks for inequality between two Sizes.

public static bool operator !=(PixelSize left, PixelSize right)

Parameters

left PixelSize

The first size.

right PixelSize

The second size.

Returns

bool

True if the sizes are unequal; otherwise false.