DemaConsulting.CanvasNet 0.1.0-beta.1

Prefix Reserved
This is a prerelease version of DemaConsulting.CanvasNet.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package DemaConsulting.CanvasNet --version 0.1.0-beta.1
                    
NuGet\Install-Package DemaConsulting.CanvasNet -Version 0.1.0-beta.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DemaConsulting.CanvasNet" Version="0.1.0-beta.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DemaConsulting.CanvasNet" Version="0.1.0-beta.1" />
                    
Directory.Packages.props
<PackageReference Include="DemaConsulting.CanvasNet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DemaConsulting.CanvasNet --version 0.1.0-beta.1
                    
#r "nuget: DemaConsulting.CanvasNet, 0.1.0-beta.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DemaConsulting.CanvasNet@0.1.0-beta.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DemaConsulting.CanvasNet&version=0.1.0-beta.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=DemaConsulting.CanvasNet&version=0.1.0-beta.1&prerelease
                    
Install as a Cake Tool

CanvasNet

GitHub forks GitHub stars GitHub contributors License Build Quality Gate Security NuGet

.NET canvas library for loading, saving, and cropping images

Overview

CanvasNet is a .NET library providing a mutable, span-based 32-bit RGBA pixel buffer along with codecs for loading and saving images in common file formats. It's designed for fast, allocation-conscious image operations using Span<T>, and supports independent-copy cropping for load/crop/save workflows.

Features

  • 🖼️ Pixel Buffer - Mutable 32-bit RGBA Surface with span-based row access
  • ✂️ Cropping - Independent-copy cropping for load/crop/save workflows
  • 🌈 Compositing - Vectorized alpha premultiply/unpremultiply and Porter-Duff "over" compositing (surface-over-surface and surface-over-constant-color)
  • 📀 BMP Codec - Load and save 24-bit and 32-bit uncompressed Windows BMP files
  • 🎨 PNG Codec - Load and save 8-bit Truecolor (RGB) and Truecolor-with-alpha (RGBA) PNG files
  • 🖨️ TIFF Codec - Load and save 8-bit RGB/RGBA/Grayscale TIFF files with PackBits/LZW/Deflate
  • 🗜️ JPEG Codec - Load baseline/progressive JPEG and save baseline 4:2:0 JPEG with quality control
  • 🔍 Header-Only Probing - GetInfo reads only image headers (dimensions/channels/alpha) without decoding pixel data, letting callers triage untrusted files before calling Load
  • ⚡ Span-Based - Fast, allocation-conscious row and pixel access
  • 🔄 Multi-Target - Supports .NET 8, 9, and 10
  • 📦 NuGet Ready - Easy integration via NuGet package

Installation

dotnet add package DemaConsulting.CanvasNet

Or via Package Manager Console:

Install-Package DemaConsulting.CanvasNet

Usage

using DemaConsulting.CanvasNet.Canvas;
using DemaConsulting.CanvasNet.Codecs;
using System.IO;

var surface = new Surface(4, 4);
surface[1, 1] = new Rgba32(255, 0, 0, 255); // set a red, opaque pixel
var cropped = surface.Crop(0, 0, 2, 2);     // independent 2x2 copy

BmpCodec.Save(surface, "surface.bmp");        // save as a 32-bit BMP file
var reloaded = BmpCodec.Load("surface.bmp"); // load it back

PngCodec.Save(surface, "surface.png");        // save as an RGBA PNG file
var reloadedPng = PngCodec.Load("surface.png"); // load it back

TiffCodec.Save(surface, "surface.tiff");        // save as an RGBA TIFF file
var reloadedTiff = TiffCodec.Load("surface.tiff"); // load it back

JpegCodec.Save(surface, "surface.jpg", 90);        // save as a baseline JPEG file
var reloadedJpeg = JpegCodec.Load("surface.jpg"); // load it back

// Triage an untrusted file's header before decoding pixel data:
var info = PngCodec.GetInfo("untrusted.png"); // reads only the header, never decodes IDAT
if (info.Width > Surface.MaxDimension
    || info.Height > Surface.MaxDimension
    || (long)info.Width * info.Height > (long)Surface.MaxDimension * Surface.MaxDimension)
{
    throw new InvalidDataException("Image dimensions exceed the supported maximum.");
}

var safeSurface = PngCodec.Load("untrusted.png"); // safe to decode fully

Building

pwsh ./build.ps1

API Documentation

Detailed API documentation for all public types and members is distributed in the api/ folder of the NuGet package.

User Guide

The CanvasNet User Guide is available on the CanvasNet releases page.

Contributing

Contributions are welcome. See CONTRIBUTING.md for development setup, coding standards, and the pull request process.

License

Copyright (c) DEMA Consulting. Licensed under the MIT License. See LICENSE for details.

By contributing to this project, you agree that your contributions will be licensed under the MIT License.

Support

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (9)

Showing the top 5 NuGet packages that depend on DemaConsulting.CanvasNet:

Package Downloads
DemaConsulting.CanvasNet.Pdf

DemaConsulting.CanvasNet.Pdf provides a decode/rasterize-only PDF page-rendering codec for the CanvasNet canvas-based drawing and rendering API.

DemaConsulting.CanvasNet.Svg

DemaConsulting.CanvasNet.Svg provides a decode/rasterize-only SVG codec for the CanvasNet canvas-based drawing and rendering API.

DemaConsulting.DocDown.Pdf.Rendering

Optional PDF page rendering (rasterization) for DEMA Consulting DocDown

DemaConsulting.Rendering.CanvasNet

CanvasNet raster renderers (PNG and JPEG) for the DEMA Consulting rendering library, with an embedded Noto Sans font for pixel-identical output

DemaConsulting.CanvasNet.Charts

DemaConsulting.CanvasNet.Charts provides a format-agnostic charting data model, builder, and renderer for the CanvasNet canvas-based drawing and rendering API.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-beta.11 80 10/9/2026
0.1.0-beta.10 118 10/7/2026
0.1.0-beta.9 75 10/7/2026
0.1.0-beta.8 163 10/4/2026
0.1.0-beta.7 66 10/4/2026
0.1.0-beta.6 59 10/3/2026
0.1.0-beta.5 62 10/2/2026
0.1.0-beta.4 60 9/28/2026
0.1.0-beta.3 316 9/26/2026
0.1.0-beta.2 65 9/25/2026
0.1.0-beta.1 67 9/20/2026