d2phap/ImageGlass · error · NotSupportedException

The image is too large to open: {fullInfo.Width:n0}x{fullInf

Error message

The image is too large to open: {fullInfo.Width:n0}x{fullInfo.Height:n0} ({megaPixels:n0} MP) needs {(double)fullInfo.Width * fullInfo.Height * fullInfo.BytesPerPixel / 1024 / 1024 / 1024:n2} GB in one buffer, but the renderer cannot address more than 2 GB per image. This format cannot be decoded at a reduced size.

What it means

Thrown by SkiaCodec.GetDecodableImageInfo when an image's full pixel buffer would exceed int.MaxValue (~2 GB) and no native decode scale fits under the cap. Skia cannot address a single bitmap over 2 GB regardless of free RAM. The method first tries the codec's native scales (JPEG IDCT eighths, largest-first); if none fits it throws NotSupportedException listing width, height, megapixels, and the required buffer size in GB. Non-JPEG codecs echo the full size back, so they cannot scale and always hit this path on large inputs.

Source

Thrown at source/ImageGlass.Lib/Common/Photoing/Codecs/SkiaCodecs/SkiaCodec.cs:299

        var fullInfo = codec.Info;
        if (FitsInPixelBuffer(fullInfo)) return fullInfo;

        foreach (var candidate in NATIVE_DECODE_SCALES)
        {
            var size = codec.GetScaledDimensions(candidate);

            // codecs without native scaling just echo the full size back
            if (size.Width >= fullInfo.Width || size.Width <= 0 || size.Height <= 0) continue;

            var scaledInfo = fullInfo.WithSize(size.Width, size.Height);
            if (!FitsInPixelBuffer(scaledInfo)) continue;

            scale = (double)size.Width / fullInfo.Width;
            return scaledInfo;
        }

        var megaPixels = (double)fullInfo.Width * fullInfo.Height / 1_000_000;
        throw new NotSupportedException(
            $"The image is too large to open: {fullInfo.Width:n0}x{fullInfo.Height:n0} "
            + $"({megaPixels:n0} MP) needs {(double)fullInfo.Width * fullInfo.Height * fullInfo.BytesPerPixel / 1024 / 1024 / 1024:n2} GB "
            + $"in one buffer, but the renderer cannot address more than 2 GB per image. "
            + $"This format cannot be decoded at a reduced size.");
    }


    /// <summary>
    /// Checks whether a full pixel buffer for the info stays within Skia's byte-size ceiling.
    /// </summary>
    private static bool FitsInPixelBuffer(SKImageInfo info)
    {
        return (long)info.Width * info.Height * info.BytesPerPixel <= MAX_PIXEL_BUFFER_BYTES;
    }


    /// <summary>
    /// Returns the linear scale that brings a <c>width * height * bytesPerPixel</c> buffer

View on GitHub (pinned to 4a3c4fecef)

Solutions

  1. Pre-process the file in an external tool to downsample or crop it below the 2 GB buffer ceiling before opening.
  2. Convert the source to JPEG so Skia can use native IDCT scaling (1/8...7/8) and decode a reduced size.
  3. Split multi-page TIFFs and open a single page, or tile the image.
  4. For formats ImageGlass routes through Magick, rely on the in-place resize path which lands closer to the ceiling.

Example fix

// before
var photo = await Core.Photos.LoadAsync(hugePngPath);

// after
// downsample offline first, e.g. via Magick.NET:
// using var m = new MagickImage(hugePngPath);
// m.Resize(8000, 8000); m.Write(smallerJpgPath);
var photo = await Core.Photos.LoadAsync(smallerJpgPath);
Defensive patterns

Strategy: validation

Validate before calling

long EstimateBufferBytes(string path)
{
    using var c = SKCodec.Create(path);
    var info = c.Info;
    return (long)info.Width * info.Height * info.BytesPerPixel;
}
// if EstimateBufferBytes(path) > int.MaxValue and the codec is not JPEG, expect this throw

Try / catch

try { photo = await Core.Photos.LoadAsync(path); }
catch (NotSupportedException ex) when (ex.Message.Contains("too large to open"))
{ /* prompt user to downsample or convert to JPEG */ }

Prevention

When it happens

Trigger: Opening a very large non-JPEG image (PNG, TIFF, BMP) whose full buffer exceeds 2 GB, e.g. a 30k x 30k RGBA PNG (~3.6 GB); a JPEG so large that even 1/8 decode exceeds 2 GB.

Common situations: Scientific stitching/microscopy TIFFs; print-resolution artwork exported as PNG; satellite imagery; large scanned documents saved as uncompressed BMP/TIFF.

Related errors


AI-assisted analysis of d2phap/ImageGlass@4a3c4fecef (2026-08-13). Data as JSON: /api/errors/c5d2b5598938fa15. Report an issue: GitHub.