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
Fields
Empty
A size representing zero
public static readonly PixelSize Empty
Field Value
Properties
AspectRatio
Gets the aspect ratio of the size.
public double AspectRatio { get; }
Property Value
Height
Gets the height.
public int Height { get; }
Property Value
Width
Gets the width.
public int Width { get; }
Property Value
Methods
Equals(PixelSize)
Returns a boolean indicating whether the size is equal to the other given size.
public bool Equals(PixelSize other)
Parameters
other
PixelSizeThe 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
objectThe 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
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
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
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
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
stringThe string.
Returns
Exceptions
ToSize(Vector)
public Size ToSize(Vector scale)
Parameters
scale
VectorThe scaling factor.
Returns
- Size
The device-independent size.
ToSize(double)
public Size ToSize(double scale)
Parameters
scale
doubleThe scaling factor.
Returns
- Size
The device-independent size.
ToSizeWithDpi(Vector)
public Size ToSizeWithDpi(Vector dpi)
Parameters
dpi
VectorThe dots per inch.
Returns
- Size
The device-independent size.
ToSizeWithDpi(double)
public Size ToSizeWithDpi(double dpi)
Parameters
dpi
doubleThe 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
stringThe string to parse.
result
PixelSizeThe result of parsing. if
source
is not validresult
is Empty
Returns
WithHeight(int)
Returns a new PixelSize with the same width and the specified height.
public PixelSize WithHeight(int height)
Parameters
height
intThe height.
Returns
WithWidth(int)
Returns a new PixelSize with the same height and the specified width.
public PixelSize WithWidth(int width)
Parameters
width
intThe width.
Returns
Operators
operator ==(PixelSize, PixelSize)
Checks for equality between two PixelSizes.
public static bool operator ==(PixelSize left, PixelSize right)
Parameters
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
Returns
- bool
True if the sizes are unequal; otherwise false.