babalae/better-genshin-impact · warning · InvalidDataException
图片像素数量超过 {MaxPixelCount:N0} 限制。
Error message
图片像素数量超过 {MaxPixelCount:N0} 限制。 What it means
Thrown by ValidateImage when the downloaded image's pixel count (width * height) exceeds MaxPixelCount (40,000,000). This is a decompression-bomb guard: it rejects images that would consume excessive memory when decoded, before they can be loaded as a WPF banner.
Source
Thrown at BetterGenshinImpact/Service/BannerImageService.cs:208
UseDefaultCredentials = false
})
{
Timeout = Timeout.InfiniteTimeSpan
};
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("BetterGI-Banner", "1.0"));
return client;
}
private static void ValidateImage(string path)
{
try
{
var imageInfo = Image.Identify(path)
?? throw new InvalidDataException("下载内容不是有效的图片。");
var pixelCount = checked((long)imageInfo.Width * imageInfo.Height);
if (pixelCount > MaxPixelCount)
{
throw new InvalidDataException($"图片像素数量超过 {MaxPixelCount:N0} 限制。");
}
}
catch (UnknownImageFormatException ex)
{
throw new InvalidDataException("下载内容不是支持的图片格式。", ex);
}
}
private static void TryDeleteFile(string path)
{
try
{
if (File.Exists(path))
{
File.Delete(path);
}
}
catch (IOException)View on GitHub (pinned to a7cb36712d)
Solutions
- Downscale the source image so width * height is under 40,000,000 (e.g. resize to 3840x2160 = ~8.3M pixels).
- Use a banner-optimized image with a typical desktop aspect ratio at a reasonable resolution.
- If a higher cap is genuinely needed, raise the MaxPixelCount constant — but be aware of the memory cost when WPF decodes it.
Defensive patterns
Strategy: validation
Validate before calling
// After Image.Identify, reject early before any caller tries to decode.
var info = Image.Identify(path) ?? throw new InvalidDataException("下载内容不是有效的图片。");
if ((long)info.Width * info.Height > MaxPixelCount)
{
throw new InvalidDataException($"图片像素数量超过 {MaxPixelCount:N0} 限制。");
} Try / catch
try
{
ValidateImage(tempPath);
}
catch (InvalidDataException ex) when (ex.Message.Contains("像素数量"))
{
logger.LogWarning("Banner image exceeds pixel limit; ask user to downscale");
} Prevention
- Pre-scale banner images to a desktop-appropriate resolution (e.g. 1920x1080 or 3840x2160) before hosting.
- Document the 40M-pixel cap in the UI next to the URL input so users know the limit.
- If a higher cap is required, raise MaxPixelCount deliberately and audit WPF memory usage.
When it happens
Trigger: The downloaded image has very high resolution, e.g. 7000x6000 = 42M pixels. The checked multiplication guards against integer overflow before comparing against the cap.
Common situations: User selects a high-resolution photograph or a stitched panorama as the custom banner; source image is a raw scan or print-ready artwork.
Related errors
- 下载内容不是有效的图片。
- 下载内容不是支持的图片格式。
- milliseconds 不能小于 0
- 不被 Locator 支持的识别类型: {RecognitionObject.RecognitionType}
- 等待 {targetDescription} 超时({timeout}ms)
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/29719874e4a1115f.
Report an issue: GitHub.