Quick Start
Quick Start
This page walks through the smallest working example: probing a file for its format and header properties, then seeing how the library handles a damaged file instead of throwing.
Probe a file
ImageProbe is the single static entry point. ProbeFile reads just enough of the
file header to populate an ImageInfo result — it never decodes pixel data:
using Aspose.Imaging.Foss;
var info = ImageProbe.ProbeFile("photo.jpg");
Console.WriteLine($"{info.Format}: {info.Width}x{info.Height}, {info.BitDepth}-bit");ImageInfo exposes Format, Width, Height, BitDepth, and FrameCount —
populated only when the detected format actually carries that data.
Probe a stream or byte array
Probe accepts a Stream or a byte[] directly, and DetectFormat returns just the
ImageFormat when you don’t need the full header:
using Aspose.Imaging.Foss;
using System.IO;
byte[] bytes = File.ReadAllBytes("photo.jpg");
var format = ImageProbe.DetectFormat(bytes);
using var stream = File.OpenRead("photo.jpg");
var info = ImageProbe.Probe(stream);Handling truncated or malformed input
ImageProbe never throws on malformed or truncated input. Instead of raising an
exception, it returns a partial ImageInfo with whatever fields it managed to read —
Format is always set when the header’s format marker was recognized, even if the
rest of the file is cut short:
using Aspose.Imaging.Foss;
byte[] truncated = fullGifBytes[..^2]; // last two bytes missing
var info = ImageProbe.Probe(truncated);
Console.WriteLine(info.Format); // Gif — detected from the header aloneThis makes ImageProbe safe to run against untrusted or partially-downloaded files
without wrapping every call in a try/catch.
Next Steps
- Installation — package setup and environment requirements
- Developer Guide — the full format detection API
- License — MIT license terms