Interface IImageRenderer
Renders the session's current state — loaded datasets, presentation, time,
and viewport — to a PNG image. Backs the render_to_image tool.
public interface IImageRenderer
Remarks
This is the seam that makes headless MCP validation possible: an agent can
open_dataset → set_palette → render → assert on the bytes with
no window and no live render loop. The desktop viewer implements it by
snapshotting its live Mapsui map; the CLI implements it over the same
headless Skia pipeline its render command already uses — which is why
the CLI path runs in CI where a GUI screenshot cannot.
Rendering never mutates session state. The method returns null when there is nothing to render (no viewport / zero size); the calling tool maps that to a not-ready error.
Properties
PreferredSize
The renderer's preferred output size in pixels when the caller omits both dimensions, or null when it has none.
(int Width, int Height)? PreferredSize { get; }
Property Value
Remarks
The desktop viewer backs this with its live on-screen viewport size, so an
unsized render_to_image matches what the user sees pixel-for-pixel
(rather than letterboxing a fixed default against a differently shaped
viewport) and can be echoed back so an agent can request a matching aspect
ratio or feed the dimensions to a pixel pick. A headless renderer has no
on-screen viewport and returns null, leaving the calling
tool to apply its fixed default. Default-implemented as
null so only hosts with a live viewport need override it.
Methods
RenderToPngAsync(int, int, double, CancellationToken)
Renders the current view to PNG-encoded bytes at the requested size.
Task<byte[]?> RenderToPngAsync(int widthPx, int heightPx, double pixelDensity, CancellationToken cancellationToken = default)
Parameters
widthPxintOutput width in pixels.
heightPxintOutput height in pixels.
pixelDensitydoubleDisplay pixel-density multiplier (
1.0= device-independent pixels;2.0= HiDPI).cancellationTokenCancellationTokenCancels the render.