{"record":{"id":"480ba7803b01d775","repo":"LykosAI/StabilityMatrix","slug":"unsupported-skalphatype-image-alphatype","errorCode":null,"errorMessage":"Unsupported SKAlphaType: {image.AlphaType}","messagePattern":"Unsupported SKAlphaType: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/Extensions/SkiaExtensions.cs","lineNumber":228,"sourceCode":"            using var bitmap = SKBitmap.FromImage(image);\n            return bitmap.ToAvaloniaBitmap(dpi);\n        }\n\n        // ReSharper disable once SwitchExpressionHandlesSomeKnownEnumValuesWithExceptionInDefault\n        var avaloniaColorFormat = image.ColorType switch\n        {\n            SKColorType.Rgba8888 => PixelFormat.Rgba8888,\n            SKColorType.Bgra8888 => PixelFormat.Bgra8888,\n            _ => throw new NotSupportedException($\"Unsupported SKColorType: {image.ColorType}\"),\n        };\n\n        // ReSharper disable once SwitchExpressionHandlesSomeKnownEnumValuesWithExceptionInDefault\n        var avaloniaAlphaFormat = image.AlphaType switch\n        {\n            SKAlphaType.Opaque => AlphaFormat.Opaque,\n            SKAlphaType.Premul => AlphaFormat.Premul,\n            SKAlphaType.Unpremul => AlphaFormat.Unpremul,\n            _ => throw new NotSupportedException($\"Unsupported SKAlphaType: {image.AlphaType}\"),\n        };\n\n        var result = new WriteableBitmap(\n            new PixelSize(image.Width, image.Height),\n            dpi,\n            avaloniaColorFormat,\n            avaloniaAlphaFormat\n        );\n\n        using var framebuffer = result.Lock();\n        CopyPixelRows(\n            pixmap.GetPixels(),\n            pixmap.RowBytes,\n            framebuffer.Address,\n            framebuffer.RowBytes,\n            image.Height\n        );\n        return result;","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/Extensions/SkiaExtensions.cs#L210-L246","documentation":"In the SKImage->WriteableBitmap conversion, ToAvaloniaBitmap maps image.AlphaType to an Avalonia AlphaFormat; only Opaque, Premul, and Unpremul are handled and any other value throws NotSupportedException naming the alpha type. Like error 16, this normally indicates an uninitialized or out-of-range SKAlphaType on the source image.","triggerScenarios":"Calling ToAvaloniaBitmap on an SKImage with an invalid/unknown AlphaType (uninitialized SKImageInfo, raw interop values, or a new enum member from a different SkiaSharp version).","commonSituations":"Interop with native Skia handles carrying out-of-range alpha values; hand-rolled SKImageInfo structs; SkiaSharp version drift after dependency upgrades.","solutions":["Create the SKImage through supported APIs (Decode/Snapshot) so AlphaType is valid.","Recreate the image with an explicit SKImageInfo { AlphaType = SKAlphaType.Premul } before converting.","Pre-check image.AlphaType with Enum.IsDefined before conversion."],"exampleFix":"// before\nvar bmp = image.ToAvaloniaBitmap();\n\n// after\nif (!Enum.IsDefined(typeof(SKAlphaType), image.AlphaType))\n    image = image.Rasterize??.Recreate(SKAlphaType.Premul); // or decode anew with SKAlphaType.Premul\nvar bmp = image.ToAvaloniaBitmap();","handlingStrategy":"type-guard","validationCode":"if (!Enum.IsDefined(typeof(SKAlphaType), image.AlphaType))\n    throw new InvalidOperationException(\"Invalid SKAlphaType on source image.\");","typeGuard":"static bool HasValidAlpha(this SKImage img) => img.AlphaType is SKAlphaType.Opaque or SKAlphaType.Premul or SKAlphaType.Unpremul;","tryCatchPattern":"try\n{\n    return image.ToAvaloniaBitmap();\n}\ncatch (NotSupportedException ex)\n{\n    logger.LogWarning(ex, \"Bad image alpha type; re-decoding with Premul\");\n    return RecreateWithPremul(image).ToAvaloniaBitmap();\n}","preventionTips":["Build SKImages through Decode/Snapshot, not hand-filled infos","Validate AlphaType after native interop","Keep SkiaSharp versions consistent across dependencies"],"tags":["skiasharp","avalonia","alpha-type","not-supported"],"backgroundTag":"unsupported-enum-value","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}