ConsoleImage
ConsoleMonster.Graphics
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
- Extension method ConsoleImage.Height
- Extension method ConsoleImage.Width
- Method ConsoleImage.FromFile
- Method GraphicsFluent.Height
- Method GraphicsFluent.Width
Accepted by parameters 4
- Extension method ConsoleImage.Height
- Extension method ConsoleImage.Width
- Method GraphicsFluent.Height
- Method GraphicsFluent.Width
Constructors
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[]
- The encoded image.
- name string? = null
- 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
- The RGBA pixels.
- name string? = null
- 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
- A PNG, JPEG, GIF, BMP, TIFF or PPM file.
public Size Measure(Constraints constraints, RenderContext context) #Returns the size the widget wants within the constraints.
Parameters
- constraints ConsoleMonster.Layout.Constraints
- The space offered.
- context ConsoleMonster.Canvas.RenderContext
- Profile, theme and glyphs.
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
- The target region.
- context ConsoleMonster.Canvas.RenderContext
- 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
- The profile, or null for Terminal.GetCurrentProfile.
- writer ConsoleMonster.Output.ITerminalWriter? = null
- The sink, or null for the console. The caller keeps ownership of a given writer.
Inherited Methods
Properties
public string Name { get; } #The name shown by the text placeholder, [image: name WxH].
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
- The instance.
- value int
- The value.
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
- The instance.
- value int
- The value.
Examples
// C# initializer or property // C# fluent
consoleImage.Width = value; consoleImage.Width(value);