AvaloniaUI/Avalonia · error · NotSupportedException

Pixel format {finalFormat} is not supported

Error message

Pixel format {finalFormat} is not supported

What it means

In WriteableBitmap.CreatePlatformImpl, after the platform backend rejects the format, Avalonia checks PixelFormatReader.SupportsFormat(finalFormat). If even the software reader cannot handle it, NotSupportedException is thrown — meaning neither the hardware nor the software fallback can use this format.

Source

Thrown at src/Avalonia.Base/Media/Imaging/WriteableBitmap.cs:138

            return new WriteableBitmap(ri.LoadWriteableBitmapToHeight(stream, height, interpolationMode));
        }

        private static (IBitmapImpl, BitmapMemory?) CreatePlatformImpl(PixelSize size, in Vector dpi, PixelFormat? format, AlphaFormat? alphaFormat)
        {
            if (size.Width <= 0 || size.Height <= 0)
                throw new ArgumentException("Size should be >= (1,1)", nameof(size));
            
            var ri = GetFactory();

            PixelFormat finalFormat = format ?? ri.DefaultPixelFormat;
            AlphaFormat finalAlphaFormat = alphaFormat ?? ri.DefaultAlphaFormat;

            if (ri.IsSupportedBitmapPixelFormat(finalFormat))
                return (ri.CreateWriteableBitmap(size, dpi, finalFormat, finalAlphaFormat), null);

            if (!PixelFormatReader.SupportsFormat(finalFormat))
                throw new NotSupportedException($"Pixel format {finalFormat} is not supported");

            finalAlphaFormat = finalFormat.HasAlpha ? finalAlphaFormat : Platform.AlphaFormat.Opaque;

            var impl = ri.CreateWriteableBitmap(size, dpi, PixelFormat.Rgba8888, finalAlphaFormat);
            return (impl, new BitmapMemory(finalFormat, finalAlphaFormat, size));
        }

        private static IPlatformRenderInterface GetFactory()
        {
            return AvaloniaLocator.Current.GetRequiredService<IPlatformRenderInterface>();
        }
    }
}

View on GitHub (pinned to 11c5427268)

Solutions

  1. Use a standard PixelFormat (Rgba8888/Bgra8888/Rgb24/Bgr24/etc.).
  2. Confirm the format is supported by the active render backend (IPlatformRenderInterface.IsSupportedBitmapPixelFormat).
  3. Avoid constructing PixelFormat with custom enum values for WriteableBitmap.

Example fix

// before
new WriteableBitmap(customFormat, AlphaFormat.Premultiplied, size, dpi); // unsupported everywhere

// after
new WriteableBitmap(PixelFormat.Bgra8888, AlphaFormat.Premultiplied, size, dpi);
Defensive patterns

Strategy: validation

Validate before calling

var ri = AvaloniaLocator.Current.GetRequiredService<IPlatformRenderInterface>();
if (!ri.IsSupportedBitmapPixelFormat(format) && !PixelFormatReader.SupportsFormat(format))
    throw new NotSupportedException($"Format {format} not supported by platform or software fallback.");

Type guard

static bool IsSupportedFormat(PixelFormat f)
{
    var ri = AvaloniaLocator.Current.GetRequiredService<IPlatformRenderInterface>();
    return ri.IsSupportedBitmapPixelFormat(f) || PixelFormatReader.SupportsFormat(f);
}

Prevention

When it happens

Trigger: Constructing a WriteableBitmap with a PixelFormat not natively supported by IPlatformRenderInterface and also not present in the software reader's switch (see errors 283/284).

Common situations: Passing a custom PixelFormat instance whose FormatEnum is none of the known values; using a format enum value added in a newer version than the reader supports; mixing platform-specific formats across backends.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/9040cc0bda23f860. Report an issue: GitHub.