Skip to content

Commit 292ae83

Browse files
committed
Update docs with image file loading and Image Viewer demo
1 parent 223d4f5 commit 292ae83

5 files changed

Lines changed: 78 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ cd MyApp && dotnet run
124124
| **Data** | ListControl, TreeControl, TableControl (interactive DataGrid with virtual data, sorting, editing), HorizontalGridControl |
125125
| **Navigation** | MenuControl, ToolbarControl, TabControl |
126126
| **Layout** | ColumnContainer, SplitterControl, ScrollablePanelControl, PanelControl |
127-
| **Drawing** | CanvasControl |
127+
| **Drawing** | CanvasControl, ImageControl (PNG/JPEG/BMP/GIF/WebP/TIFF via ImageSharp) |
128128
| **Advanced** | SpectreRenderableControl (wraps any Spectre.Console `IRenderable`), ProgressBarControl, TerminalControl |
129129

130130
## API Usage

docs/CONTROLS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Controls for custom graphics and free-form drawing.
7171
| Control | Description | Details |
7272
|---------|-------------|---------|
7373
| **[CanvasControl](controls/CanvasControl.md)** | Free-form drawing surface | 30+ drawing primitives, retained & immediate modes, thread-safe async painting |
74-
| **[ImageControl](IMAGE_RENDERING.md)** | Half-block image renderer | Displays PixelBuffer as 2-pixels-per-cell image with Fit/Fill/Stretch/None scaling |
74+
| **[ImageControl](IMAGE_RENDERING.md)** | Half-block image renderer | Load PNG/JPEG/BMP/GIF/WebP/TIFF files or PixelBuffer; Fit/Fill/Stretch/None scaling |
7575

7676
## Layout Controls
7777

docs/EXAMPLES.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,31 @@ dotnet run --project Examples/CanvasDemo
239239

240240
---
241241

242+
#### Image Viewer (DemoApp)
243+
Load and display real image files in the terminal using half-block Unicode rendering.
244+
245+
![Image Viewer](images/examples/imageviewer.png)
246+
247+
```bash
248+
dotnet run --project Examples/DemoApp
249+
# Navigate to Rendering → Image Viewer
250+
```
251+
252+
**Key Features:**
253+
- Load PNG, JPEG, BMP, GIF, WebP, TIFF files via file picker dialog
254+
- Half-block rendering (2 vertical pixels per character cell)
255+
- Four scale modes: Fit, Fill, Stretch, None
256+
- Resizable window with live image rescaling
257+
- Keyboard shortcuts: Ctrl+O to open, S to cycle scale, Esc to close
258+
259+
**APIs Demonstrated:**
260+
- `PixelBuffer.FromFile()` — decode image files via SixLabors.ImageSharp
261+
- `ImageControl` with `ScaleMode` switching
262+
- `FileDialogs.ShowFilePickerAsync()` with format filter
263+
- `HorizontalGridControl` for toolbar layout
264+
265+
---
266+
242267
#### CompositorEffectsExample
243268
Demonstrates compositor-style buffer manipulation capabilities.
244269

@@ -546,6 +571,7 @@ dotnet run --project Examples/PluginShowcaseExample
546571
| `MultilineEditControl` | DemoApp, TextEditorExample |
547572
| `LogViewerControl` | DemoApp |
548573
| `TabControl` | TabControlDemo |
574+
| `ImageControl` | DemoApp (Image Rendering, Image Viewer) |
549575
| `CanvasControl` | CanvasDemo |
550576
| `HorizontalGridControl` | Most examples |
551577
| `SpectreRenderableControl` | SpectreMouseExample |

docs/IMAGE_RENDERING.md

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ SharpConsoleUI can render pixel-based images in the console using Unicode half-b
66

77
1. [Overview](#overview)
88
2. [PixelBuffer](#pixelbuffer)
9-
3. [ImageControl](#imagecontrol)
10-
4. [Scale Modes](#scale-modes)
11-
5. [Alignment and Scale Mode Interaction](#alignment-and-scale-mode-interaction)
12-
6. [Half-Block Rendering](#half-block-rendering)
13-
7. [Creating Test Images](#creating-test-images)
9+
3. [Loading Images from Files](#loading-images-from-files)
10+
4. [ImageControl](#imagecontrol)
11+
5. [Scale Modes](#scale-modes)
12+
6. [Alignment and Scale Mode Interaction](#alignment-and-scale-mode-interaction)
13+
7. [Half-Block Rendering](#half-block-rendering)
14+
8. [Creating Test Images](#creating-test-images)
1415

1516
## Overview
1617

@@ -55,6 +56,50 @@ var argbArray = new int[width * height];
5556
var buffer = PixelBuffer.FromArgbArray(argbArray, width, height);
5657
```
5758

59+
## Loading Images from Files
60+
61+
SharpConsoleUI can load real image files using [SixLabors.ImageSharp](https://github.com/SixLabors/ImageSharp). Supported formats: **PNG, JPEG, BMP, GIF, TIFF, TGA, PBM, WebP**.
62+
63+
### From a File Path
64+
65+
```csharp
66+
var buffer = PixelBuffer.FromFile("photo.png");
67+
window.AddControl(Controls.Image(buffer));
68+
```
69+
70+
### From a Stream
71+
72+
```csharp
73+
using var stream = File.OpenRead("photo.jpg");
74+
var buffer = PixelBuffer.FromStream(stream);
75+
```
76+
77+
### From an ImageSharp Image
78+
79+
If you already have an `Image<Rgb24>` (e.g., after applying ImageSharp processing), convert it directly:
80+
81+
```csharp
82+
using SixLabors.ImageSharp;
83+
using SixLabors.ImageSharp.PixelFormats;
84+
85+
using var image = Image.Load<Rgb24>("photo.png");
86+
image.Mutate(x => x.Resize(200, 100)); // optional pre-processing
87+
var buffer = PixelBuffer.FromImageSharp(image);
88+
```
89+
90+
### With File Picker Dialog
91+
92+
```csharp
93+
var path = await FileDialogs.ShowFilePickerAsync(windowSystem,
94+
filter: "*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.webp;*.tiff");
95+
96+
if (path != null)
97+
{
98+
var buffer = PixelBuffer.FromFile(path);
99+
imageControl.Source = buffer;
100+
}
101+
```
102+
58103
## ImageControl
59104

60105
Add images to windows using `ImageControl`:
85.7 KB
Loading

0 commit comments

Comments
 (0)