{"record":{"id":"9040cc0bda23f860","repo":"AvaloniaUI/Avalonia","slug":"pixel-format-finalformat-is-not-supported","errorCode":null,"errorMessage":"Pixel format {finalFormat} is not supported","messagePattern":"Pixel format (.+?) is not supported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/Imaging/WriteableBitmap.cs","lineNumber":138,"sourceCode":"\n            return new WriteableBitmap(ri.LoadWriteableBitmapToHeight(stream, height, interpolationMode));\n        }\n\n        private static (IBitmapImpl, BitmapMemory?) CreatePlatformImpl(PixelSize size, in Vector dpi, PixelFormat? format, AlphaFormat? alphaFormat)\n        {\n            if (size.Width <= 0 || size.Height <= 0)\n                throw new ArgumentException(\"Size should be >= (1,1)\", nameof(size));\n            \n            var ri = GetFactory();\n\n            PixelFormat finalFormat = format ?? ri.DefaultPixelFormat;\n            AlphaFormat finalAlphaFormat = alphaFormat ?? ri.DefaultAlphaFormat;\n\n            if (ri.IsSupportedBitmapPixelFormat(finalFormat))\n                return (ri.CreateWriteableBitmap(size, dpi, finalFormat, finalAlphaFormat), null);\n\n            if (!PixelFormatReader.SupportsFormat(finalFormat))\n                throw new NotSupportedException($\"Pixel format {finalFormat} is not supported\");\n\n            finalAlphaFormat = finalFormat.HasAlpha ? finalAlphaFormat : Platform.AlphaFormat.Opaque;\n\n            var impl = ri.CreateWriteableBitmap(size, dpi, PixelFormat.Rgba8888, finalAlphaFormat);\n            return (impl, new BitmapMemory(finalFormat, finalAlphaFormat, size));\n        }\n\n        private static IPlatformRenderInterface GetFactory()\n        {\n            return AvaloniaLocator.Current.GetRequiredService<IPlatformRenderInterface>();\n        }\n    }\n}\n","sourceCodeStart":120,"sourceCodeEnd":152,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/Imaging/WriteableBitmap.cs#L120-L152","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nnew WriteableBitmap(customFormat, AlphaFormat.Premultiplied, size, dpi); // unsupported everywhere\n\n// after\nnew WriteableBitmap(PixelFormat.Bgra8888, AlphaFormat.Premultiplied, size, dpi);","handlingStrategy":"validation","validationCode":"var ri = AvaloniaLocator.Current.GetRequiredService<IPlatformRenderInterface>();\nif (!ri.IsSupportedBitmapPixelFormat(format) && !PixelFormatReader.SupportsFormat(format))\n    throw new NotSupportedException($\"Format {format} not supported by platform or software fallback.\");","typeGuard":"static bool IsSupportedFormat(PixelFormat f)\n{\n    var ri = AvaloniaLocator.Current.GetRequiredService<IPlatformRenderInterface>();\n    return ri.IsSupportedBitmapPixelFormat(f) || PixelFormatReader.SupportsFormat(f);\n}","tryCatchPattern":null,"preventionTips":["Use standard PixelFormat values for WriteableBitmap.","Confirm platform support via IPlatformRenderInterface before construction.","Do not hand-craft PixelFormat with custom enum values."],"tags":["imaging","writeablebitmap","pixelformat","notsupported"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}