DmitryBrant.ImageFormats 1.5.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package DmitryBrant.ImageFormats --version 1.5.7
                    
NuGet\Install-Package DmitryBrant.ImageFormats -Version 1.5.7
                    
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.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DmitryBrant.ImageFormats" Version="1.5.7" />
                    
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.7
                    
#r "nuget: DmitryBrant.ImageFormats, 1.5.7"
                    
#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.7
                    
#: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.7
                    
Install as a Cake Addin
#tool nuget:?package=DmitryBrant.ImageFormats&version=1.5.7
                    
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, .FIT, .FTS, .FZ (astronomical images, including image cubes, multi-extension and tile-compressed files)
  • .DCM (DICOM medical images, including JPEG, JPEG-LS, JPEG 2000 and RLE compressed ones)
  • .JP2, .J2K, .J2C, .JPF (JPEG 2000)
  • .ART (AOL Johnson-Grace images)
  • .PSP, .PSPIMAGE (Paint Shop Pro images)
  • .AWD (Microsoft Fax documents)

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 = ImageData.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);

DICOM and FITS files can contain more than one frame (for example, an ultrasound cine loop, or the planes of an astronomical image cube). ImageData.Load returns the first frame; to get at the others, use DicomReader or FitsReader directly:

int count = DicomReader.GetFrameCount("series.dcm");
ImageData frame = DicomReader.Load("series.dcm", count - 1);

// Or decode them all, one at a time, parsing the file only once:
foreach (ImageData frame in DicomReader.LoadFrames("series.dcm"))
    ...

Occasionally a source format stores its pixel data as an embedded image in some other well-known encoding that the library can't decode itself (for example, a DICOM file that wraps an 8-bit JPEG using arithmetic coding). Those bytes are passed 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.8 87 10/17/2026
1.5.7 94 10/13/2026
1.5.6 116 9/27/2026
1.5.5 97 9/27/2026
1.5.3 90 9/27/2026
1.5.1 100 9/26/2026
1.5.0 138 9/6/2026
1.1.0 122 9/5/2026
1.0.4 594 8/17/2025
1.0.3 317 3/8/2025
1.0.2 322 4/15/2024
1.0.1 281 4/15/2024