OptrisOptrisDocumentation

Documentation/OTC SDK/Optris.Sdk — C# API referencev12.0

Snapshot

public sealed class Snapshot : IDisposable

A snapshot this SDK wrote, opened for reading.

The other half of ThermalCamera.SaveSnapshot(…). Without it an application that wanted its own metadata, its own attachments or the temperatures back out of a file had to parse the metadata document and the 16-bit grid itself, reimplementing format knowledge that is already in the SDK.

The file is read once, when it is opened. Every property and method below then answers from memory, which is why this is a handle rather than a set of static helpers: asking six questions about one file should not parse it six times.

Dispose it. It holds the parsed metadata and every attachment payload; a snapshot of a 640x480 sensor with a megabyte of attachments is a megabyte of native memory until it is released.

Only PNG and TIFF can be opened. SnapshotFormat.Csv is write-only: it carries no metadata document, so there is nothing to read back.

Example

using Snapshot snapshot = Snapshot.Open("event.tiff");

Console.WriteLine(snapshot.Info.Description);

using ThermalFrame frame = snapshot.LoadThermal();
Console.WriteLine($"{frame.Width}x{frame.Height}, centre "
                  + $"{frame.GetTemperature(frame.Width / 2,
                                            frame.Height / 2):F1} C");

Snapshot: properties

public IReadOnlyList<AttachmentInfo> Attachments { get; }

The files the application attached, in the order the writer added them, not every file the snapshot carries.

The index only: reading a payload is Snapshot.ReadAttachment(…), so listing what a file carries never copies megabytes nobody asked for.

Three of the SDK's own are deliberately left out of this list, matched on name and MIME type so that an application which attached something of its own under one of those names keeps it:

  • thermal.png: on a colour snapshot, the measurement itself. It is the image's data rather than a payload, and Snapshot.LoadThermal is how to reach it.
  • characteristic-curve.otc: the camera's characteristic curve.
  • radiometry.otc: the radiometry bundle.

So for a file that carries nothing but those, this list is empty, and that is not a failure. An attachment list has always meant "the files I attached", and putting the SDK's own in front of them would shift every index and every count in code written before these existed.

All three are still in the file, and still in the attachments array of Snapshot.MetadataJson, which describes the container literally, so a reader that has never heard of this SDK can see them, and so can you.

The curve and the bundle cannot be read back as data. No binding hands you the curve's points. What you can do instead is use the curve the file carries: open the snapshot with ThermalCamera.OpenStill(…) and the measurement is redone through it, which is what makes a per-region emissivity and a different global emissivity work on a still. ThermalCamera.HonoursRegionEmissivity is how to ask whether this file carried one at all.

public PixelEncoding Encoding { get; }

What a pixel in this file means.

Ask this before reading the image: Snapshot.LoadThermal and Snapshot.ReadRawPixels each refuse the other's files rather than reinterpreting them.

public int Height { get; }

Image height in pixels, as recorded in the file.

public SnapshotInfo Info { get; }

What the file says about its own capture.

Exactly the fields ThermalCamera.SaveSnapshot(…) takes. A field the writer did not set and the camera could not supply reads back as null or an empty string.

public string MetadataJson { get; }

The full metadata document as JSON.

  • Throws ObjectDisposedException: The snapshot has been disposed.

Everything Snapshot.Info carries and everything it does not: the pixel scale, the scene statistics, the capture telemetry, the measuring regions, the attachment index and any extraJson the writer merged in. Read it when you want a field this binding does not model; use Snapshot.Info for the ones it does.

public SnapshotRender? Render { get; }

How the colorized picture in the file was drawn.

null when the file's primary image is the 16-bit greyscale one: a TIFF, or a PNG written with no live view to take a picture from. That is routine rather than a failure, which is why it is null rather than an exception.

public int Width { get; }

Image width in pixels, as recorded in the file.

Snapshot: methods

public void Dispose()

Release the file's parsed contents.

Disposing twice is safe.

public ThermalFrame LoadThermal()

Read the temperatures back as a frame.

Returns: A frame that behaves like any other, and that you dispose the same way.

  • Throws FeatureNotSupportedException: The file holds detector counts rather than temperature. Check Snapshot.Encoding, or read them with Snapshot.ReadRawPixels.
  • Throws ObjectDisposedException: The snapshot has been disposed.

Exact for every temperature file this SDK writes: the internal value that went in is the internal value that comes out, so a measurement taken from the file equals the one taken from the live frame rather than approximating it.

public static Snapshot Open(string path)

Open a snapshot and read it into memory.

  • path: A PNG or TIFF written by this SDK.

Returns: The opened snapshot. Dispose it.

  • Throws ArgumentException: path is null or empty.
  • Throws SdkIOException: The file cannot be read, or an attachment fails the SHA-256 recorded for it.
  • Throws SdkConfigurationException: The file carries no metadata document, which is how a file from before this format, or a file this SDK did not write, is recognized rather than guessed at.
public byte[] ReadAttachment(int index)

Copy one carried file's bytes out.

Returns: The file's content.

  • Throws ArgumentOutOfRangeException: index is not a position in Snapshot.Attachments.
  • Throws ObjectDisposedException: The snapshot has been disposed.
public ushort[] ReadRawPixels()

Read uncalibrated detector counts back, bit for bit.

Returns: Snapshot.Width × Snapshot.Height counts, row-major from the top-left.

  • Throws FeatureNotSupportedException: The file holds temperature rather than detector counts. Check Snapshot.Encoding, or read them with Snapshot.LoadThermal.
  • Throws ObjectDisposedException: The snapshot has been disposed.