Class FormatInfo
Describes a file format: its names, how to recognize it, and its reader and writer.
public sealed record FormatInfo : IEquatable<FormatInfo>
- Inheritance
-
FormatInfo
- Implements
- Inherited Members
Examples
// Every built-in format, with its name, extensions and MIME types; Raster.Save picks one by extension.
foreach (FormatInfo format in new[] { PngFormat.Info, JpegFormat.Info, GifFormat.Info, BmpFormat.Info, TgaFormat.Info, QoiFormat.Info, PnmFormat.Info })
{
Console.WriteLine($"{format.Name}: {string.Join(", ", format.Extensions)} ({string.Join(", ", format.MimeTypes)})");
}
// A SignatureMatcher decides from the first SignatureLength bytes whether a file is in the format.
SignatureMatcher isPng = PngFormat.Info.Matches;
bool png = isPng(File.ReadAllBytes("duck.png").AsSpan(0, PngFormat.Info.SignatureLength));
Remarks
Instances are immutable and safe to share across threads. Register custom formats with WithFormat(FormatInfo).
Properties
ConvertsColor
Gets whether the reader produces ConvertColorTo's colour space itself, as part of its own rendering (a camera RAW develop renders straight into it), so a load passes the option to the reader rather than converting the pixels it returns. Such a reader returns rasters whose metadata names that colour space. Defaults to false.
public bool ConvertsColor { get; init; }
Property Value
Extensions
Gets the file extensions without the dot, such as "png", the preferred one first. Used only to pick a writer when saving to a path.
public IReadOnlyList<string> Extensions { get; init; }
Property Value
Matches
Gets the function that recognizes the format from its first bytes. File extensions are never used for detection.
public required SignatureMatcher Matches { get; init; }
Property Value
MimeTypes
Gets the MIME types, the preferred one first.
public IReadOnlyList<string> MimeTypes { get; init; }
Property Value
Name
Gets the short name, such as "PNG". Names are matched without regard to case.
public required string Name { get; init; }
Property Value
Reader
Gets the reader, or null if the format can only be written.
public IFormatReader? Reader { get; init; }
Property Value
SignatureLength
Gets how many leading bytes Matches needs; data shorter than the longest signature registered is passed to it whole.
public required int SignatureLength { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is outside 0 to 65,536.
Writer
Gets the writer, or null if the format can only be read.
public IFormatWriter? Writer { get; init; }
Property Value
Methods
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.