PNG output display implementation for OledSharp
$ dotnet add package OledSharp.PngA .NET 8.0 implementation of IOledDisplay that outputs display content to PNG image files. This library is perfect for testing, debugging, and visualizing what would be displayed on an OLED screen without needing physical hardware.
[!IMPORTANT] This is a software implementation for testing and visualization. For the main library documentation and general usage, see OledSharp.
This library provides the PngOutputDisplay class which implements the IOledDisplay interface from the base OledSharp library. Instead of controlling physical hardware, it renders the display buffer to a PNG image file, making it ideal for development, testing, and documentation purposes.
To install the OledSharp.Png library via NuGet, run the following command in your project directory:
dotnet add package OledSharp.Png
using OledSharp.Png;
// Create PNG output display (128x64 pixels, saves to "output.png")
using (IOledDisplay display = new PngOutputDisplay("output.png", width: 128, height: 64))
{
display.Initialize();
// Create text renderer
TextRenderer renderer = new TextRenderer(display);
// Draw with word wrapping
renderer.DrawWrappedString(
x: 2, // 2 px in from the left edge
y: 2, // 2 px in from the left edge
text: "This is a long text that will wrap",
maxWidth: display.Width - 4); // 2 px from the right edge too
// Draw individual pixels
display.SetBufferPixel(10, 10, true);
display.SetBufferPixel(11, 11, true);
// Save to PNG file
display.PushBuffer();
}
PngOutputDisplay display = new PngOutputDisplay("output.png");
PngOutputDisplay display = new PngOutputDisplay("output.png", width: 256, height: 128);
PushBuffer() call overwrites the existing fileMIT License - see project file for details.