private static Bitmap ReadImageFrame(Stream stream, PNMImageInfo imageInfo)
{
try
{
// decode PNM image depending on its format
switch (imageInfo.Version)
{
case 5:
return ReadP5Image(stream, imageInfo.Width, imageInfo.Height, imageInfo.MaxDataValue);
case 6:
return ReadP6Image(stream, imageInfo.Width, imageInfo.Height, imageInfo.MaxDataValue);
}
}
catch
{
throw new ArgumentException("The stream does not contain valid PNM image.");
}
return null;
}