ImageFrame<TPixel> Class

A borrowed, typed view of one full-canvas displayed frame (or of the poster frame) of an Image<TPixel>.

public sealed class ImageFrame<TPixel> : ImageFrame where TPixel : unmanaged

Type parameters

TPixel
The pixel type.

Remarks

See ImageFrame for the lifetime and lease contract.

Inheritance
ImageFrame ImageFrame<TPixel>

Properties

NameDescription
PixelFormatGets the pixel format (always the image pixel format).

Gets the pixel format (always the image pixel format).

public override PixelFormat PixelFormat { get; }

Property value

PixelFormat

Indexers

NameDescription
this[int, int]Gets or sets a single pixel. Prefer ImageFrame<TPixel>.ProcessPixelRows for bulk access.

this[int, int]

ImageFrame{TPixel}.cs

Gets or sets a single pixel. Prefer ImageFrame<TPixel>.ProcessPixelRows for bulk access.

public TPixel this[int x, int y] { get; set; }

Parameters

x int
The column, from 0 to Width - 1.
y int
The row, from 0 to Height - 1.

Property value

TPixel

Exceptions

ArgumentOutOfRangeException
A coordinate is out of range.
InvalidOperationException
A conflicting lease is active.
ObjectDisposedException
The frame is no longer attached to a live image.

Methods

NameDescription
CopyPixelDataTo(Span<TPixel>, int)Copies the visible pixels to a caller buffer. Elements between rows (stride padding) are left untouched.
ProcessPixelRows(PixelRowsAction<TPixel>)Gives scoped read/write access to the visible pixels, row by row.
ProcessPixelRows<TState>(TState, PixelRowsAction<TPixel, TState>)Gives scoped read/write access to the visible pixels, passing caller state to avoid closure allocations.

CopyPixelDataTo(Span<TPixel>, int)

ImageFrame{TPixel}.cs

Copies the visible pixels to a caller buffer. Elements between rows (stride padding) are left untouched.

public void CopyPixelDataTo(Span<TPixel> destination, int strideInPixels = 0)

Parameters

destination Span<TPixel>
The destination buffer.
strideInPixels int
The distance between the starts of two consecutive destination rows, in pixels, or 0 for tightly packed rows. Must be 0 or at least Width.

Exceptions

ArgumentOutOfRangeException
strideInPixels is invalid.
ArgumentException
destination is too short (the last row only needs Width pixels).
InvalidOperationException
A conflicting lease is active.
ObjectDisposedException
The frame is no longer attached to a live image.

ProcessPixelRows overloads

ProcessPixelRows(PixelRowsAction<TPixel>)

ImageFrame{TPixel}.cs

Gives scoped read/write access to the visible pixels, row by row.

public void ProcessPixelRows(PixelRowsAction<TPixel> action)
Parameters
action PixelRowsAction<TPixel>
The callback. It must not be asynchronous and must not retain the spans.
Exceptions
InvalidOperationException
A conflicting lease is active.
ObjectDisposedException
The frame is no longer attached to a live image.

ProcessPixelRows<TState>(TState, PixelRowsAction<TPixel, TState>)

ImageFrame{TPixel}.cs

Gives scoped read/write access to the visible pixels, passing caller state to avoid closure allocations.

public void ProcessPixelRows<TState>(TState state, PixelRowsAction<TPixel, TState> action) where TState : allows ref struct
Type parameters
TState
The type of the state.
Parameters
state TState
The state passed to action.
action PixelRowsAction<TPixel, TState>
The callback. Use a static lambda to avoid allocations. It must not retain the spans.
Exceptions
InvalidOperationException
A conflicting lease is active.
ObjectDisposedException
The frame is no longer attached to a live image.