SceneImage Class

A raster image (PNG, JPEG, GIF or WebP), stretched to fill a rectangle, or fitted in it (SceneImage.Alignment).

public sealed class SceneImage : SceneElement

Remarks

The SVG embeds the bytes of the image as they are. The image and PDF renderers decode them: an image they cannot decode is not drawn.

Inheritance
SceneElement SceneImage

Constructors

NameDescription
SceneImage(double, double, double, double, ReadOnlyMemory<byte>)Initializes a new instance of the SceneImage class.

SceneImage(double, double, double, double, ReadOnlyMemory<byte>)

SceneImage.cs

Initializes a new instance of the SceneImage class.

public SceneImage(double x, double y, double width, double height, ReadOnlyMemory<byte> data)

Parameters

x double
The left edge.
y double
The top edge.
width double
The width.
height double
The height.
data ReadOnlyMemory<byte>
The bytes of a PNG, JPEG, GIF or WebP file.

Exceptions

ArgumentException
data does not start with the signature of a PNG, JPEG, GIF or WebP file.

Properties

NameDescription
AlignmentGets or sets how the image keeps its proportions in its rectangle, as the SVG preserveAspectRatio attribute. The default is SceneAspectRatio.None: the image is stretched to fill the rectangle.
DataGets the bytes of the image file.
HeightGets the height.
MediaTypeGets the media type of the image file: image/png, image/jpeg, image/gif or image/webp.
SliceGets or sets a value that indicates whether the image covers the whole rectangle and is cut to it (slice), rather than fitting in it (meet, the default). It does not apply when SceneImage.Alignment is SceneAspectRatio.None.
WidthGets the width.
XGets the left edge.
YGets the top edge.

Alignment

SceneImage.cs

Gets or sets how the image keeps its proportions in its rectangle, as the SVG preserveAspectRatio attribute. The default is SceneAspectRatio.None: the image is stretched to fill the rectangle.

public SceneAspectRatio Alignment { get; set; }

Property value

SceneAspectRatio

Remarks

With another value, the image is scaled by the same factor in both directions, to fit in the rectangle (or to cover it, with SceneImage.Slice), and aligned in it as the value says. The default of SVG is SceneAspectRatio.XMidYMid.

Gets the bytes of the image file.

public ReadOnlyMemory<byte> Data { get; }

Property value

ReadOnlyMemory<byte>

Gets the height.

public double Height { get; }

Property value

double

MediaType

SceneImage.cs

Gets the media type of the image file: image/png, image/jpeg, image/gif or image/webp.

public string MediaType { get; }

Property value

string

Gets or sets a value that indicates whether the image covers the whole rectangle and is cut to it (slice), rather than fitting in it (meet, the default). It does not apply when SceneImage.Alignment is SceneAspectRatio.None.

public bool Slice { get; set; }

Property value

bool

Gets the width.

public double Width { get; }

Property value

double

Gets the left edge.

public double X { get; }

Property value

double

Gets the top edge.

public double Y { get; }

Property value

double

Methods

NameDescription
GetMediaType(ReadOnlySpan<byte>)Gets the media type of an image file from its signature, or null when it is not a PNG, JPEG, GIF or WebP file.

GetMediaType(ReadOnlySpan<byte>)

SceneImage.cs

Gets the media type of an image file from its signature, or null when it is not a PNG, JPEG, GIF or WebP file.

public static string? GetMediaType(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>
The first bytes of the file, at least 12.

Returns

string? The media type, or null.