ImageFrame
public readonly struct ImageFrame
One frame of image data, borrowed for the duration of a callback.
The colorized picture, the raw sensor samples and the radiometric energy all arrive as this: they differ only in what a pixel means, which ImageFrame.Format says. Measurements arrive as a ThermalFrame instead, which carries metadata and a temperature scale that a plain buffer cannot.
The pixels are borrowed. They belong to the SDK and are valid only for the duration of the call that handed them over. Copy anything you need to keep (ImageFrame.ToArray or ImageFrame.CopyTo(…)) before returning. Holding the ImageFrame.Pixels span past that point reads memory the SDK has moved on from.
ImageFrame: properties
public int BytesPerPixel { get; }
How many bytes one pixel occupies.
public ImagePixelFormat Format { get; }
What the bytes mean.
public bool HasFrameMetadata { get; }
Whether ImageFrame.Sequence and ImageFrame.Timestamp describe the capture this frame was drawn from.
Check this before reading either of them. Zero is a real sequence number, the first frame of the stream, and a real time stamp, so neither has a value that can mean "nobody said".
true on every frame of a camera, a replay and a reopened still. false on a replay of a picture-only file (one written with the palette already in its pixels) where the decoder has no capture record to report.
public int Height { get; }
Height in pixels.
public ReadOnlySpan<byte> Pixels { get; }
The pixels, as raw bytes. Valid only until the callback that delivered this frame returns.
public uint Sequence { get; }
The capture's sequence number, the same value FrameMetadata.Sequence carries on the thermal frame of the same moment.
This is what makes a picture pairable with its measurement. The colour image and the thermal frame arrive by independent paths (this handler runs on the SDK's thread and FramesAsync is read by your code), so pairing on "the newest thermal frame I hold" is one frame late while a stream runs, and stays wrong indefinitely after a paused replay's single seeked frame.
Meaningless unless ImageFrame.HasFrameMetadata is true. This frame is borrowed for the duration of the callback, so decide the pairing here or copy this number out; it is a uint and costs nothing to keep.
public int StrideBytes { get; }
Bytes from the start of one row to the start of the next.
Equal to ImageFrame.Width times ImageFrame.BytesPerPixel for every frame this SDK produces, but read it rather than assuming so.
public TimeSpan Timestamp { get; }
When the capture was taken: the same value FrameMetadata.Timestamp carries on the thermal frame of the same moment.
A stopwatch reading, not a date. See FrameMetadata.Timestamp for what the epoch is and is not. TimeSpan.Zero unless ImageFrame.HasFrameMetadata is true.
public int Width { get; }
Width in pixels.
ImageFrame: methods
public void CopyTo(Span<byte> destination)
Copy the pixels somewhere that outlives the callback.
-
destination: Where to copy them. Must be at leastReadOnlySpan.LengthofImageFrame.Pixelsbytes. -
Throws
ArgumentException:destinationis too small.
public byte[] ToArray()
Copy the pixels into a new array.
Returns: The copy, which is yours.
Allocates. In a per-frame loop prefer ImageFrame.CopyTo(…) into a buffer you reuse.