babalae/better-genshin-impact · error · InvalidDataException

无法解码 Markdown 图片。

Error message

无法解码 Markdown 图片。

What it means

Error "无法解码 Markdown 图片。" thrown in babalae/better-genshin-impact.

Source

Thrown at BetterGenshinImpact/View/Controls/Markdown/MarkdownImageLoader.cs:220

                using var image = SixLabors.ImageSharp.Image.Load<Bgra32>(bytes);
                ValidatePixelCount(image.Width, image.Height);
                var pixels = new byte[checked(image.Width * image.Height * 4)];
                image.CopyPixelDataTo(pixels);
                var bitmapSource = BitmapSource.Create(
                    image.Width,
                    image.Height,
                    96,
                    96,
                    WpfPixelFormats.Bgra32,
                    null,
                    pixels,
                    image.Width * 4);
                bitmapSource.Freeze();
                return new MarkdownImageResult(bitmapSource, image.Width, image.Height);
            }
            catch (Exception imageSharpException)
            {
                throw new InvalidDataException("无法解码 Markdown 图片。", imageSharpException);
            }
        }
    }

    private static void ValidatePixelCount(int width, int height)
    {
        if (width <= 0 || height <= 0 || (long)width * height > MaxPixelCount)
        {
            throw new InvalidDataException("图片像素尺寸无效或超过安全限制。");
        }
    }

    private static string GetCacheKey(Uri source)
    {
        if (!source.IsFile)
        {
            return source.AbsoluteUri;
        }

View on GitHub (pinned to a7cb36712d)

Solutions

  1. 确认图片文件未损坏,可用看图软件打开验证
  2. 转换为常见格式(PNG/JPEG)后重试
  3. 检查图片是否为加密的特殊格式

Example fix

用图片查看器验证该图片能正常打开;重新导出/下载图片。

When it happens

Trigger: WPF BitmapDecoder 解码失败后回退 ImageSharp 解码仍失败,抛出“无法解码”的 InvalidDataException(附内部异常)。

Common situations: 图片文件本身损坏、不是有效图片格式(如把HTML当图片)。


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/07deada02dac3507. Report an issue: GitHub.