DmitryBrant.ImageFormats
1.6.4
dotnet add package DmitryBrant.ImageFormats --version 1.6.4
NuGet\Install-Package DmitryBrant.ImageFormats -Version 1.6.4
<PackageReference Include="DmitryBrant.ImageFormats" Version="1.6.4" />
<PackageVersion Include="DmitryBrant.ImageFormats" Version="1.6.4" />
<PackageReference Include="DmitryBrant.ImageFormats" />
paket add DmitryBrant.ImageFormats --version 1.6.4
#r "nuget: DmitryBrant.ImageFormats, 1.6.4"
#:package DmitryBrant.ImageFormats@1.6.4
#addin nuget:?package=DmitryBrant.ImageFormats&version=1.6.4
#tool nuget:?package=DmitryBrant.ImageFormats&version=1.6.4
imageformats
.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)
- .PSD, .PSB, .PDD (Adobe Photoshop and PhotoDeluxe images)
- .FLI, .FLC (Autodesk Animator animations)
- .FPX (FlashPix images)
- .PPP (Serif PagePlus publications; reads the preview image stored in the file)
- .TIF, .TIFF (TIFF images, including BigTIFF, multi-page, tiled, CCITT, LZW, Deflate and JPEG compressed ones)
- .SER (Lucam Recorder videos, as used for planetary imaging, including raw Bayer ones)
- .CIN, .CINE (Phantom high-speed camera videos, including raw color and packed 10-bit ones)
- .DDS (DirectDraw Surface textures, including BC1 to BC7 compressed ones, cube maps, texture arrays and volume textures)
- .LFP, .LFR (Lytro light field camera pictures, both raw ones and refocus stacks)
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, FITS, FLI/FLC, TIFF, SER, Cine, DDS and Lytro files can contain more than one frame (for
example, an ultrasound cine loop, the planes of an astronomical image cube, an animation,
the pages of a fax, a planetary or high-speed video, the faces of a cube map, or the focal
planes of a refocusable picture).
ImageData.Load returns the first frame (or, for a refocusable Lytro picture, the one
focused at its default depth); to get at the others, use DicomReader,
FitsReader, FliReader, TiffReader, SerReader, CineReader, DdsReader or
LfpReader 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"))
...
Photoshop files normally contain a flattened copy of the picture, which is what
ImageData.Load returns. When that copy is missing or only a placeholder (as in PhotoDeluxe
files, or Photoshop files saved without "Maximize Compatibility"), the layers are composited
instead. To make that choice yourself, use PsdReader directly:
ImageData image = PsdReader.Load("picture.psd", PsdImageSource.Layers);
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
License: MIT
| Product | Versions 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. |
-
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.6.4 | 45 | 10/28/2026 |
| 1.6.3 | 65 | 10/26/2026 |
| 1.6.1 | 95 | 10/24/2026 |
| 1.5.8 | 119 | 10/17/2026 |
| 1.5.7 | 100 | 10/13/2026 |
| 1.5.6 | 122 | 9/27/2026 |
| 1.5.5 | 98 | 9/27/2026 |
| 1.5.3 | 90 | 9/27/2026 |
| 1.5.1 | 102 | 9/26/2026 |
| 1.5.0 | 152 | 9/6/2026 |
| 1.1.0 | 128 | 9/5/2026 |
| 1.0.4 | 597 | 8/17/2025 |
| 1.0.3 | 321 | 3/8/2025 |
| 1.0.2 | 324 | 4/15/2024 |
| 1.0.1 | 284 | 4/15/2024 |