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
- Use a standard PixelFormat (Rgba8888/Bgra8888/Rgb24/Bgr24/etc.).
- Confirm the format is supported by the active render backend (IPlatformRenderInterface.IsSupportedBitmapPixelFormat).
- 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
- Use standard PixelFormat values for WriteableBitmap.
- Confirm platform support via IPlatformRenderInterface before construction.
- Do not hand-craft PixelFormat with custom enum values.
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
- Pixel format {format} is not supported
- Pixel format {format} is not supported
- CopyPixels is not supported for this bitmap type
- CopyPixels is not supported for transcoded bitmaps
- stride
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/9040cc0bda23f860.
Report an issue: GitHub.