1. Products
  2.   Aspose.Imaging
  3.   Aspose.Imaging FOSS for .NET

Aspose.Imaging FOSS for .NET

Zero-dependency .NET library for detecting image formats and reading header metadata — dimensions, bit depth, frame count — directly from the file header, without decoding pixels. MIT licensed.

Aspose.Imaging FOSS — Open Source .NET Image Format Detection Library

Aspose.Imaging FOSS for .NET identifies an image file’s format and reads its basic header properties — dimensions, bit depth, and frame count — directly from the file header, without decoding a single pixel. The static ImageProbe class is the entry point: ProbeFile(path) reads from disk, Probe(stream) and Probe(data) accept a stream or byte array, and DetectFormat(stream) / DetectFormat(data) return just the ImageFormat enum value when dimensions aren’t needed. Every probe method returns an ImageInfo object with nullable Width, Height, BitDepth, and FrameCount properties, populated only when the detected format actually carries that value.

The library detects 11 formats — PNG, JPEG, GIF, BMP, WebP (lossy, lossless, and extended), ICO, TIFF, PSD, EMF, WMF, and DICOM — covering formats with no other FOSS .NET detector, such as PSD, EMF/WMF, and DICOM, with Implicit VR Little Endian and Explicit VR Little/Big Endian transfer syntax coverage. Probe never throws on malformed or truncated input: if a file matches a format’s signature but its header can’t be fully parsed, the result carries just the detected Format rather than an exception.

Aspose.Imaging FOSS for .NET is MIT-licensed with zero NuGet dependencies and targets both netstandard2.0 and net8.0. It is intentionally scoped to format detection only — for decoding, editing, or converting these image formats, see Aspose.Imaging for .NET — Enterprise Product.

Format Detection API

  • File-based probing: ImageProbe.ProbeFile(path) reads a file from disk and returns an ImageInfo.
  • Stream and byte-array probing: ImageProbe.Probe(stream) and ImageProbe.Probe(data) accept a seekable or non-seekable stream, or a raw byte array.
  • Format-only detection: ImageProbe.DetectFormat(stream) and ImageProbe.DetectFormat(data) return just the ImageFormat enum value without building a full ImageInfo.
  • Structured results: ImageInfo exposes Format, plus nullable Width, Height, BitDepth, and FrameCount — populated only when the format actually carries that data.

When You Need Fast Format Detection

  • Upload validation: Confirm an uploaded file really is an image, and of a recognized format, before passing it to a heavier pipeline.
  • Thumbnail sizing: Read Width/Height from a file header to lay out a UI without loading the full image.
  • Batch triage: Sort a directory of mixed image files by detected format without decoding any of them.
  • Medical imaging intake: Read DICOM Rows/Columns/BitsAllocated from a file header for fast pre-processing checks.

Broad, Resilient Format Coverage

Field population varies by format — every format is detected, but only some carry bit depth or frame count in their header. See the field support table below for the exact breakdown.

  • Formats with no other FOSS .NET detector: PSD, EMF/WMF, and DICOM are covered alongside the common raster formats.
  • DICOM transfer syntax coverage: Implicit VR Little Endian and Explicit VR Little/Big Endian, including common compressed variants whose non-pixel elements are Explicit VR Little Endian.
  • Never throws on malformed input: Probe returns an ImageInfo with just Format set, rather than an exception, when a file matches a format signature but its header can’t be fully parsed.

Where Resilience Matters

  • Untrusted uploads: Probe user-submitted files without a single malformed header crashing the request.
  • Partial downloads: Detect the format of a truncated or in-progress file transfer.
  • Legacy file archives: Identify old PSD, EMF, or WMF files mixed into a general-purpose archive.
  • Multi-frame media: Read FrameCount for animated GIFs, ICO, and TIFF, and branch downstream logic on the result.

Detect a Format and Read Header Metadata from a File

Install the package, then probe a file from disk.

git clone https://github.com/aspose-imaging-foss/Aspose.Imaging-Foss-for-.NET.git
cd Aspose.Imaging-Foss-for-.NET
dotnet build
using Aspose.Imaging.Foss;
var info = ImageProbe.ProbeFile("photo.jpg");
Console.WriteLine($"{info.Format}: {info.Width}x{info.Height}, {info.BitDepth}-bit");

Detect a Format from a Stream or Byte Array

DetectFormat and Probe accept a seekable or non-seekable stream, or a raw byte array.

using Aspose.Imaging.Foss;
var format = ImageProbe.DetectFormat(bytes);
var info2 = ImageProbe.Probe(stream);

Field Support by Format

FormatWidth / HeightBit depthFrame count
PNG
JPEG
GIF
BMP
WebP
ICO
TIFF
PSD
EMF✓ (from bounds)
WMF (placeable)✓ (assumes 96 DPI)
DICOM✓ (Rows/Columns)✓ (BitsAllocated)
  

Support and Learning Resources