Skip to content
ConsoleMonster
Class

ConsoleImage

ConsoleMonster.Graphics

Namespace
ConsoleMonster.Graphics
Assembly
ConsoleMonster.Graphics
Implements
IWidget
Modifiers
sealed

An image drawn inline at a size in cells, keeping its aspect ratio. ConsoleImage.Write prints it with the best protocol the profile allows (TerminalProfile.ImageProtocol): Kitty, iTerm2 or Sixel pixels in terminals that support them, half blocks on any other 256-colour terminal, and a text placeholder in redirected, CI or no-colour output.

Inheritance

  • object
  • ConsoleImage

Remarks

As a widget inside layouts, dashboards and live regions it always draws half blocks (or the placeholder): those outputs diff and redraw cells, so an image stays exact on refresh and an unchanged image writes nothing. Terminal pixels are print-once only.

Usage

Explore 9 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Returned or exposed by 5

Accepted by parameters 4

Constructors

ConsoleImage 2 overloads
public ConsoleImage(byte[] encoded, string? name = null) #

Creates an image from encoded PNG, JPEG, GIF, BMP, TIFF or PPM bytes, for example a ChartForgeX ToPng() render.

Parameters

encoded byte[] required
The encoded image.
name string? = null optional
The name shown by the text placeholder.

Exceptions

  • NotSupportedException – The bytes are not an image format ChartForgeX decodes.
  • InvalidDataException – The image is damaged or truncated.
public ConsoleImage(RgbaImage image, string? name = null) #

Creates an image from decoded pixels, for example a ChartForgeX raster render. The pixels are copied.

Parameters

image ChartForgeX.Raster.RgbaImage required
The RGBA pixels.
name string? = null optional
The name shown by the text placeholder.

Methods

public static ConsoleImage FromFile(string path) #

Reads an image file; the file name becomes ConsoleImage.Name.

Parameters

path string required
A PNG, JPEG, GIF, BMP, TIFF or PPM file.

Returns

ConsoleImage The image.
public Size Measure(Constraints constraints, RenderContext context) #

Returns the size the widget wants within the constraints.

Parameters

constraints ConsoleMonster.Layout.Constraints required
The space offered.
context ConsoleMonster.Canvas.RenderContext required
Profile, theme and glyphs.

Returns

Size The desired size, never larger than the constraints.
public void Render(Region region, RenderContext context) #

Renders into a region. The region may be smaller or larger than the measured size.

Parameters

region ConsoleMonster.Canvas.Region required
The target region.
context ConsoleMonster.Canvas.RenderContext required
Profile, theme and glyphs.
public void Write(TerminalProfile? profile = null, ITerminalWriter? writer = null) #

Prints the image once below the current output: Kitty, iTerm2 or Sixel pixels when the profile allows them, else the half blocks or placeholder every other output gets. While a live session owns the console the image goes above it as half blocks. To choose a protocol, pass Terminal.GetCurrentProfile().WithImageProtocol(...).

Parameters

profile ConsoleMonster.Capabilities.TerminalProfile? = null optional
The profile, or null for Terminal.GetCurrentProfile.
writer ConsoleMonster.Output.ITerminalWriter? = null optional
The sink, or null for the console. The caller keeps ownership of a given writer.

Properties

public string Name { get; } #

The name shown by the text placeholder, [image: name WxH].

public int PixelWidth { get; } #

The source width in pixels.

public int PixelHeight { get; } #

The source height in pixels.

public int Width { get; set; } #

The width in cells, or 0 to follow ConsoleImage.Height or one cell per 10 pixels. Always within the space offered.

public int Height { get; set; } #

The height in cells, or 0 to follow the width. With both set, the image fits inside that box.

public string Placeholder { get; } #

The placeholder written where pixels cannot be drawn.

Extension Methods

public static ConsoleImage Height(ConsoleImage consoleImage, int value) #

Sets ConsoleImage.Height: The height in cells, or 0 to follow the width. With both set, the image fits inside that box.

Parameters

consoleImage ConsoleMonster.Graphics.ConsoleImage required
The instance.
value int required
The value.

Returns

ConsoleImage The same instance.

Examples

// C# initializer or property    // C# fluent
consoleImage.Height = value;     consoleImage.Height(value);
public static ConsoleImage Width(ConsoleImage consoleImage, int value) #

Sets ConsoleImage.Width: The width in cells, or 0 to follow ConsoleImage.Height or one cell per 10 pixels. Always within the space offered.

Parameters

consoleImage ConsoleMonster.Graphics.ConsoleImage required
The instance.
value int required
The value.

Returns

ConsoleImage The same instance.

Examples

// C# initializer or property    // C# fluent
consoleImage.Width = value;      consoleImage.Width(value);