Introduction
Aspose.Imaging FOSS for .NET is a free, MIT-licensed, open-source library for .NET developers
who need to know what an image file is — its format, dimensions, bit depth, and frame count —
without paying the cost of decoding it. 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 the ImageFormat enum value
without building a full ImageInfo, for callers that only need to branch on format. Every probe
method returns an ImageInfo object with nullable Width, Height, BitDepth, and FrameCount
properties, populated only when the detected format’s header actually carries that value.
This is a deliberately narrow tool, and that’s the point. It does not decode pixels, render images, or convert between formats — for that, the commercial Aspose.Imaging for .NET product is the right choice (linked below under Open Source & Licensing). What Aspose.Imaging FOSS for .NET does is the much smaller, much more common job of answering “what format is this, and how big is it?” as fast and as safely as possible, for the class of problem where full decoding would be wasted work: validating an upload, sizing a thumbnail layout, triaging a batch of mixed files, or reading DICOM header fields for a pre-processing check.
The library is MIT-licensed with zero external dependencies and targets both netstandard2.0 and
net8.0 — free for both open-source and commercial use, with no royalties or redistribution
restrictions.
Key Features
Three Ways to Probe a File
ImageProbe offers file-path, stream, and byte-array entry points, so it fits wherever the image
data already lives in your pipeline — on disk, already in memory, or arriving over the wire.
DetectFormat skips building a full ImageInfo when you only need to branch on format.
using Aspose.Imaging.Foss;
var fromPath = ImageProbe.ProbeFile("photo.jpg");
var fromBytes = ImageProbe.Probe(byteArray);
var fromStream = ImageProbe.Probe(stream);
var formatOnly = ImageProbe.DetectFormat(byteArray); // ImageFormat only, no header parse
Structured, Honest Results
ImageInfo exposes Format (an ImageFormat enum value, always set once the header is
recognized) alongside nullable Width, Height, BitDepth, and FrameCount. “Nullable” is
doing real work here: field population genuinely varies by format, and ImageInfo never
fabricates a value a format’s header doesn’t carry. Checking for null before use is the correct
pattern, not a defensive afterthought.
var info = ImageProbe.ProbeFile("scan.dcm");
if (info.Width.HasValue && info.Height.HasValue)
{
Console.WriteLine($"{info.Format}: {info.Width}x{info.Height}");
}
11 Formats, Including Three Nothing Else in the FOSS .NET Space Detects
PNG, JPEG, GIF, BMP, WebP (lossy, lossless, and extended), ICO, TIFF, PSD, EMF, WMF, and DICOM.
Field population differs by format on purpose, not by omission — PNG carries width, height, bit
depth, and frame count (though FrameCount is a hardcoded 1, not real animated-PNG frame
detection); JPEG and BMP carry dimensions and bit depth but never a frame count; WebP carries only
dimensions; ICO’s FrameCount is a genuine count of the embedded icon sizes in its directory, and
a 0 byte in an ICO directory entry’s dimension field means 256px, per the format spec; TIFF’s
FrameCount reflects a bounded walk of the file’s IFD chain, one IFD per page.
Three of these eleven — PSD, EMF/WMF, and DICOM — have no other free, open-source .NET detector that we’re aware of, which is a real part of why this library exists.
WMF and EMF: Two Legacy Formats, Two Different Limits
Non-placeable WMF is still correctly identified as ImageFormat.Wmf, but only placeable WMF
populates dimensions — derived from the header’s units-per-inch bounds via a hardcoded 96 DPI
conversion, since WMF itself carries no absolute pixel size. EMF has no explicit width/height
field at all; its dimensions come from the rclBounds device-space rectangle in the EMF header
instead. Both are honestly reflected in ImageInfo: when a value can’t be derived, the property
stays null rather than guessing.
DICOM Header Parsing Without a Viewer
ImageProbe reads DICOM headers across Implicit VR Little Endian and Explicit VR Little/Big
Endian transfer syntaxes, extracting Rows into Height, Columns into Width, and
BitsAllocated into BitDepth — no DICOM viewer or external imaging dependency required. Parsing
is conservative by design: an undefined-length sequence element stops the walk rather than
guessing at its contents, so a partially-understood DICOM file degrades to a partial ImageInfo
instead of a wrong one.
Never Throws on Malformed or Truncated Input
Probe is built for untrusted, partial, or in-flight files. If a file matches a format’s
signature but its header can’t be fully parsed — a truncated download, a corrupted upload — the
result carries just the detected Format rather than an exception.
byte[] truncated = fullFileBytes[..^3];
var info = ImageProbe.Probe(truncated);
// info.Format is still populated; other fields may be null
Quick Start
Install the package, then probe a file from disk to read its detected format, dimensions, bit depth, and frame count in one call, followed by a format-only check using the raw bytes:
git clone https://github.com/aspose-imaging-foss/Aspose.Imaging-Foss-for-.NET.git
cd Aspose.Imaging-Foss-for-.NET
dotnet buildusing Aspose.Imaging.Foss;
var info = ImageProbe.ProbeFile("photo.jpg");
Console.WriteLine($"{info.Format}: {info.Width}x{info.Height}, {info.BitDepth}-bit, " +
$"{info.FrameCount ?? 0} frame(s)");
// Format-only detection when dimensions aren't needed
var bytes = File.ReadAllBytes("photo.jpg");
var format = ImageProbe.DetectFormat(bytes);
Supported Formats
Aspose.Imaging FOSS for .NET detects all 11 formats below and reads header-level metadata — it does not decode pixel data, so there is no “write” capability to report. Field population varies by format; see the detailed breakdown in Key Features above.
| Format | Extension | Detected | Width / Height | Bit depth | Frame count |
|---|---|---|---|---|---|
| PNG | .png | ✓ | ✓ | ✓ | ✓ |
| JPEG | .jpg / .jpeg | ✓ | ✓ | ✓ | — |
| GIF | .gif | ✓ | ✓ | — | ✓ |
| BMP | .bmp | ✓ | ✓ | ✓ | — |
| WebP | .webp | ✓ | ✓ | — | — |
| ICO | .ico | ✓ | ✓ | ✓ | ✓ |
| TIFF | .tif / .tiff | ✓ | ✓ | ✓ | ✓ |
| PSD | .psd | ✓ | ✓ | ✓ | — |
| EMF | .emf | ✓ | ✓ (from bounds) | — | — |
| WMF | .wmf | ✓ | ✓ (placeable only, 96 DPI) | — | — |
| DICOM | .dcm | ✓ | ✓ (Rows/Columns) | ✓ (BitsAllocated) | — |
Open Source & Licensing
Aspose.Imaging FOSS for .NET is MIT-licensed with zero external dependencies. MIT licensing permits use in both open-source and commercial projects with no royalties or restrictions on redistribution. The source is available on GitHub. It is intentionally scoped to format detection only — for decoding, editing, or converting these image formats, see Aspose.Imaging for .NET — Enterprise Product.