DotImage 0.1.0

dotnet add package DotImage --version 0.1.0
                    
NuGet\Install-Package DotImage -Version 0.1.0
                    
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="DotImage" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotImage" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="DotImage" />
                    
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 DotImage --version 0.1.0
                    
#r "nuget: DotImage, 0.1.0"
                    
#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 DotImage@0.1.0
                    
#: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=DotImage&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=DotImage&version=0.1.0
                    
Install as a Cake Tool

DotImage

A C# port of Go's standard library image package for .NET 8 and .NET 10.

DotImage provides 2D image types, color models, Porter–Duff compositing, and PNG, GIF, and JPEG codecs. The implementation follows Go's logic closely while exposing an idiomatic C# API (IImage, Memory<byte>, exceptions).

Features

  • Core image typesRgbaImage, NrgbaImage, GrayImage, CmykImage, PalettedImage, YCbCrImage, and more
  • ColorIColor, color models, RGB↔YCbCr, RGB↔CMYK, Plan9 and WebSafe palettes
  • DrawingDrawOps.Draw, DrawMask, Clip, Floyd–Steinberg dithering
  • Codecs — PNG (all color types, interlaced, 16-bit), GIF (animation), JPEG (baseline + progressive decode)
  • Auto-detect decodeFormatRegistry.Decode sniffs magic bytes and dispatches to the registered codec

Requirements

Build & Test

dotnet build
dotnet test

Tests run on both net8.0 and net10.0 (209 tests).

Quick Start

Decode any supported format

PNG, GIF, and JPEG formats register automatically on the first call to FormatRegistry.Decode or DecodeConfig.

using DotImage;

using var stream = File.OpenRead("photo.png");
var (image, format) = FormatRegistry.Decode(stream);

Console.WriteLine($"{format}: {image.Bounds().Dx()}×{image.Bounds().Dy()}");

var (r, g, b, a) = image.At(0, 0).Rgba();

Decode config only (check dimensions before allocating)

using var stream = File.OpenRead("photo.jpg");
var (config, format) = FormatRegistry.DecodeConfig(stream);

Console.WriteLine($"{format}: {config.Width}×{config.Height}");

Create and draw on an image

using DotImage;
using DotImage.Color;
using DotImage.Draw;

var rect = Geometry.Rect(0, 0, 256, 256);
var dst = Images.NewRgba(rect);

DrawOps.Draw(dst, rect, UniformImages.White, Point.Origin, Op.Src);
DrawOps.Draw(dst, new Rect(new Point(64, 64), new Point(192, 192)), UniformImages.Black, Point.Origin, Op.Over);

Encode PNG

using DotImage.Png;

using var output = File.Create("output.png");
PngWriter.Encode(output, image);

Encode JPEG

using DotImage.Jpeg;

using var output = File.Create("output.jpg");
JpegWriter.Encode(output, image, new JpegOptions { Quality = 90 });

Decode GIF animation

using DotImage.Gif;

using var stream = File.OpenRead("animation.gif");
var gif = GifReader.DecodeAll(stream);

foreach (var frame in gif.Image)
{
    // process each frame
}

Project Structure

DotImage/
├── DotImage.slnx
├── src/DotImage/
│   ├── Color/           # color models, palettes, YCbCr/CMYK
│   ├── Draw/            # compositing
│   ├── Png/             # PNG codec
│   ├── Gif/             # GIF codec
│   ├── Jpeg/            # JPEG codec
│   ├── Compress/        # GIF LZW
│   ├── Util/            # YCbCr→RGBA fast paths
│   ├── Image.cs         # concrete image buffer types
│   ├── Geom.cs          # Point, Rect
│   ├── Format.cs        # FormatRegistry
│   └── ...
└── tests/DotImage.Tests/

API Mapping (Go → C#)

Go DotImage
image.Image IImage
image.NewRGBA(r) Images.NewRgba(r)
image.Decode(r) FormatRegistry.Decode(stream)
color.Color IColor
image.Rectangle Rect
draw.Draw(...) DrawOps.Draw(...)
png.Decode(r) PngReader.Decode(stream)
jpeg.Encode(w, m, &opts) JpegWriter.Encode(stream, image, options)
gif.DecodeAll(r) GifReader.DecodeAll(stream)

Relationship to Go

This library is a faithful port of Go's image tree:

Go package DotImage namespace
image DotImage
image/color DotImage.Color
image/draw DotImage.Draw
image/png DotImage.Png
image/gif DotImage.Gif
image/jpeg DotImage.Jpeg

Key differences from Go:

  • Errors are thrown as exceptions instead of returned as error values
  • Pixel buffers use byte[] (slice via Memory<byte> where applicable)
  • Format registration is lazy (on first decode) instead of Go blank imports

License

The original Go source code is Copyright © The Go Authors and distributed under a BSD-style license.

This C# port retains the same license terms. See LICENSE and NOTICE for details.

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 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 60 9/7/2026