ImageData Class

A rectangle of pixels (https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#imagedata): its width, its height, and its pixels, row by row, 4 components per pixel (R, G, B, A, not premultiplied), as bytes or half-precision floats.

public sealed class ImageData

Remarks

The pixels are shared with the scripts: an ImageData created from a Uint8ClampedArray views its bytes, and the array returned by the data attribute to the scripts is the one the .NET code reads and writes (ImageData.Data).

See also

Constructors

NameDescription
ImageData(object, uint, uint?, ImageDataSettings?)Creates an image data viewing pixels (https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-imagedata-with-data): the Uint8ClampedArray or Float16Array of a script, or bytes (an array or a Memory<T> of bytes, which are not copied).
ImageData(uint, uint, ImageDataSettings?)Creates an image data of transparent black pixels (https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-imagedata).

ImageData overloads

ImageData(object, uint, uint?, ImageDataSettings?)

ImageData.cs

Creates an image data viewing pixels (https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-imagedata-with-data): the Uint8ClampedArray or Float16Array of a script, or bytes (an array or a Memory<T> of bytes, which are not copied).

public ImageData(object data, uint sw, uint? sh = null, ImageDataSettings? settings = null)
Parameters
data object
The pixels.
sw uint
The width in pixels.
sh uint?
The height in pixels, or null to compute it from the length of the data.
settings ImageDataSettings?
The color space and the format of the pixels (the format of the data).
Exceptions
DomException
An InvalidStateError when the number of components is not a nonzero multiple of 4 or the format does not match the array, an IndexSizeError when the number of pixels is not a multiple of the width or does not match the height.
See also

ImageData(uint, uint, ImageDataSettings?)

ImageData.cs

Creates an image data of transparent black pixels (https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-imagedata).

public ImageData(uint sw, uint sh, ImageDataSettings? settings = null)
Parameters
sw uint
The width in pixels.
sh uint
The height in pixels.
settings ImageDataSettings?
The color space and the format of the pixels.
Exceptions
DomException
An IndexSizeError when the width or the height is 0 or the pixels are too large.
See also

Properties

NameDescription
ColorSpaceGets the color space of the pixels.
DataGets the bytes of the pixels: 4 bytes per pixel (R, G, B, A) for ImageDataPixelFormat.RgbaUnorm8, 4 half-precision floats (Half, in the byte order of the platform) for ImageDataPixelFormat.RgbaFloat16. The bytes are shared with the array of the scripts; they are empty when its buffer is detached.
DataArrayGets the array of the pixels for the scripts (https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-imagedata-data): use ImageData.Data in .NET code.
HeightGets the height in pixels.
PixelFormatGets the format of the pixels.
WidthGets the width in pixels.

ColorSpace

ImageData.cs

Gets the bytes of the pixels: 4 bytes per pixel (R, G, B, A) for ImageDataPixelFormat.RgbaUnorm8, 4 half-precision floats (Half, in the byte order of the platform) for ImageDataPixelFormat.RgbaFloat16. The bytes are shared with the array of the scripts; they are empty when its buffer is detached.

public Memory<byte> Data { get; }

Property value

Memory<byte>

DataArray

ImageData.cs

Gets the array of the pixels for the scripts (https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-imagedata-data): use ImageData.Data in .NET code.

public object DataArray { get; }

Gets the height in pixels.

public uint Height { get; }

PixelFormat

ImageData.cs

Gets the width in pixels.

public uint Width { get; }