Enum RecoveryMode
How a reader handles damaged data.
public enum RecoveryMode
Fields
Lenient = 0Return what was decoded when the data ends early or a checksum fails after valid pixels, and note the problem in Warnings. Data that would need guessing, such as an invalid header, still throws.
Strict = 1Throw CorruptDataException on any problem.
Examples
EgamiContext strict = EgamiContext.Default with
{
Limits = SafetyLimits.Default with { MaxPixels = 25_000_000, MaxTotalBytes = 256L * 1024 * 1024 },
};
try
{
// Read the header first: cheap, and it rejects what you do not want before any pixel memory is used.
RasterInfo info = Raster.Probe(upload, strict);
if (info.Width > 8000 || info.Height > 8000)
{
throw new InvalidDataException("Too large.");
}
using Raster image = Raster.Load(upload, strict, new ReaderOptions { Recovery = RecoveryMode.Strict });
Console.WriteLine($"{info.Format.Name} {image.Width} × {image.Height}");
}
catch (UnsupportedFormatException)
{
Console.WriteLine("Not an image format we accept.");
}
catch (LimitExceededException e)
{
Console.WriteLine($"Over the {e.LimitName} limit.");
}
catch (CorruptDataException e)
{
Console.WriteLine($"Damaged at byte {e.Offset}.");
}