NickeManarin/ScreenToGif · error · NoNullAllowedException

Unable to determine image format

Error message

Unable to determine image format

What it means

ImageMethods loads an image with Image.FromFile(fileName, true) and maps its RawFormat.Guid against a fixed whitelist (Bmp, Gif, Icon, Jpeg, Png). If the GUID matches none, it throws NoNullAllowedException("Unable to determine image format"). The whitelist deliberately excludes TIFF, WMF, EMF, EXIF, WebP and memory-bitmap formats.

Source

Thrown at ScreenToGif/ImageUtil/ImageMethods.cs:1372

        // Check the image format to determine what format
        // the image will be saved to the memory stream in
        var guidToImageFormatMap = new Dictionary<Guid, ImageFormat>()
        {
            {ImageFormat.Bmp.Guid,  ImageFormat.Bmp},
            {ImageFormat.Gif.Guid,  ImageFormat.Png},
            {ImageFormat.Icon.Guid, ImageFormat.Png},
            {ImageFormat.Jpeg.Guid, ImageFormat.Jpeg},
            {ImageFormat.Png.Guid,  ImageFormat.Png}
        };

        using (var gifImg = Image.FromFile(fileName, true))
        {
            var imageGuid = gifImg.RawFormat.Guid;

            var imageFormat = (from pair in guidToImageFormatMap where imageGuid == pair.Key select pair.Value).FirstOrDefault();

            if (imageFormat == null)
                throw new NoNullAllowedException("Unable to determine image format");

            //Get the frame count
            var dimension = new FrameDimension(gifImg.FrameDimensionsList[0]);
            var frameCount = gifImg.GetFrameCount(dimension);

            //Step through each frame
            for (var i = 0; i < frameCount; i++)
            {
                //Set the active frame of the image and then
                gifImg.SelectActiveFrame(dimension, i);

                //write the bytes to the tmpFrames array
                using (var ms = new MemoryStream())
                {
                    gifImg.Save(ms, imageFormat);
                    tmpFrames.Add(ms.ToArray());
                }
            }

View on GitHub (pinned to a4d0a67c21)

Solutions

  1. Convert the source image to PNG or JPEG before importing.
  2. Extend guidToImageFormatMap with TIFF/WMF/EXIF entries if those formats must be supported.
  3. Pre-validate the format and show a user-friendly message listing supported formats instead of throwing NoNullAllowedException.
  4. If the file is corrupt, re-export it from the original source.

Example fix

// before
var guidToImageFormatMap = new Dictionary<Guid, ImageFormat>()
{
    {ImageFormat.Bmp.Guid,  ImageFormat.Bmp},
    {ImageFormat.Gif.Guid,  ImageFormat.Png},
    {ImageFormat.Icon.Guid, ImageFormat.Png},
    {ImageFormat.Jpeg.Guid, ImageFormat.Jpeg},
    {ImageFormat.Png.Guid,  ImageFormat.Png}
};
...
if (imageFormat == null)
    throw new NoNullAllowedException("Unable to determine image format");

// after
var guidToImageFormatMap = new Dictionary<Guid, ImageFormat>()
{
    {ImageFormat.Bmp.Guid,  ImageFormat.Bmp},
    {ImageFormat.Gif.Guid,  ImageFormat.Png},
    {ImageFormat.Icon.Guid, ImageFormat.Png},
    {ImageFormat.Jpeg.Guid, ImageFormat.Jpeg},
    {ImageFormat.Png.Guid,  ImageFormat.Png},
    {ImageFormat.Tiff.Guid, ImageFormat.Png},
    {ImageFormat.Exif.Guid, ImageFormat.Jpeg}
};
...
if (imageFormat == null)
    throw new NotSupportedException($"Unsupported image format (Guid {imageGuid}). Supported: BMP, GIF, ICO, JPEG, PNG, TIFF.");
Defensive patterns

Strategy: validation

Validate before calling

using var probe = Image.FromFile(fileName, true);
var supported = new[] { ImageFormat.Bmp, ImageFormat.Gif, ImageFormat.Icon, ImageFormat.Jpeg, ImageFormat.Png }
    .Any(f => f.Guid == probe.RawFormat.Guid);
if (!supported) /* reject with a clear message listing supported formats */

Type guard

static bool IsSupportedRawFormat(Image img) =>
    ImageFormat.Bmp.Guid == img.RawFormat.Guid ||
    ImageFormat.Gif.Guid == img.RawFormat.Guid ||
    ImageFormat.Icon.Guid == img.RawFormat.Guid ||
    ImageFormat.Jpeg.Guid == img.RawFormat.Guid ||
    ImageFormat.Png.Guid == img.RawFormat.Guid;

Try / catch

try { return ImageMethods.ImportFromFile(fileName); }
catch (NoNullAllowedException ex) when (ex.Message.Contains("image format"))
{ /* prompt user to convert to PNG/JPEG */ }

Prevention

When it happens

Trigger: Opening/importing an image whose RawFormat.Guid is not in {Bmp, Gif, Icon, Jpeg, Png}. Common for .tiff/.tif, .webp, .wmf, .emf, .exif, or images whose RawFormat resolves to ImageFormat.MemoryBmp.

Common situations: User drops a TIFF/WEBP/WMF file into the editor; image saved by another tool with a non-standard raw format GUID; corrupted file whose header GUID is garbage; screenshot tools that emit EXIF-tagged JPEGs that report a different GUID.

Related errors


AI-assisted analysis of NickeManarin/ScreenToGif@a4d0a67c21 (2026-08-13). Data as JSON: /api/errors/b8bfad5e253af521. Report an issue: GitHub.