DmitryBrant.ImageFormats 1.5.0

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

imageformats

Build NuGet Downloads

.NET modules for decoding obscure graphics formats:

  • .PPM, .PGM, .PBM (Netpbm images)
  • .TGA (Targa)
  • .PCX (ZSoft Paintbrush)
  • .IFF (Amiga ILBM images)
  • .SGI, .RGB, .BW (SGI images)
  • .RAS (Sun raster images)
  • .MAC (MacPaint)
  • .CUT (Dr. Halo)
  • .XPM (X Window PixMap)
  • .DEEP (TVPaint IFF DEEP images)
  • .FITS (experimental support)
  • .DICOM (experimental support)
  • .ART (AOL Johnson-Grace images)
  • .PSP, .PSPIMAGE (Paint Shop Pro images)

Usage

Every decoder returns an ImageData object: a plain buffer of raw pixels, with no dependency on any particular imaging library. Hand the buffer to whichever library you prefer.

using DmitryBrant.ImageFormats;

// Detects the format automatically, and returns null if it isn't one we know.
ImageData image = Picture.Load("picture.tga");

The pixels in image.Data are stored top-down, one row after another, four bytes per pixel in blue, green, red, alpha order. (Read as a 32-bit little-endian integer, that's the usual packed ARGB layout.) This is the same layout as GDI+ Format32bppArgb, WIC/Direct2D B8G8R8A8, Avalonia's Bgra8888, and ImageSharp's Bgra32, so it can go straight into any of them:

// Avalonia
var bitmap = new WriteableBitmap(new PixelSize(image.Width, image.Height),
    new Vector(96, 96), PixelFormat.Bgra8888, AlphaFormat.Unpremul);
using (var buffer = bitmap.Lock())
    for (int y = 0; y < image.Height; y++)
        Marshal.Copy(image.Data, y * image.Stride, buffer.Address + (y * buffer.RowBytes), image.Stride);

// ImageSharp
var bitmap = Image.LoadPixelData<Bgra32>(image.Data, image.Width, image.Height);

// System.Drawing
var bitmap = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb);
var bits = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, bitmap.PixelFormat);
for (int y = 0; y < image.Height; y++)
    Marshal.Copy(image.Data, y * image.Stride, bits.Scan0 + (y * bits.Stride), image.Stride);
bitmap.UnlockBits(bits);

A few source formats store their pixel data as an embedded image in some other well-known encoding, most notably DICOM files that wrap a JPEG. Rather than pull in a JPEG decoder, the library passes those bytes through untouched: image.IsEncoded is true, image.Data is null, and the encoded bytes are in image.EncodedData (with image.EncodedFormat naming the encoding) for you to decode yourself.

The ImageViewer project in this repository is a small Avalonia app that does all of the above; see its Interop.cs for a complete example.

Copyright 2013+ Dmitry Brant

https://dmitrybrant.com

License: MIT

Product Compatible and additional computed target framework versions.
.NET 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.
  • net10.0

    • No dependencies.

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
1.5.0 121 9/6/2026
1.1.0 105 9/5/2026
1.0.4 561 8/17/2025
1.0.3 309 3/8/2025
1.0.2 315 4/15/2024
1.0.1 268 4/15/2024