babalae/better-genshin-impact · warning · Exception
ReadImageMatWithResizeSync: 不支持的插值算法 {interpolation}
Error message
ReadImageMatWithResizeSync: 不支持的插值算法 {interpolation} What it means
This error is thrown by ReadImageMatWithResizeSync when the interpolation argument falls outside the valid range of 0–5 (OpenCV InterpolationFlags: Nearest=0, Linear=1, Cubic=2, Area=3, Lanczos=4, ExactLinear=5). It is a pre-condition guard before calling Cv2.Resize. Note: the throw is wrapped in a try/catch in the same method — the exception is logged and an empty Mat is returned, so the caller never actually sees the exception propagate.
Source
Thrown at BetterGenshinImpact/Core/Script/Dependence/LimitedFile.cs:260
/// <item><description>双线性插值 (1) - 默认</description></item>
/// <item><description>双三次插值 (2)</description></item>
/// <item><description>像素区域关系重采样 (3)</description></item>
/// <item><description>Lanczos插值 (4)</description></item>
/// <item><description>精确双线性插值 (5)</description></item>
/// </list>
/// </remarks>
public Mat ReadImageMatWithResizeSync(string path, double width, double height, int interpolation = 1)
{
try
{
if (width <= 0 || height <= 0)
{
throw new Exception("ReadImageMatWithResizeSync: 宽度和高度必须为正数");
}
if (interpolation is < 0 or > 5)
{
throw new Exception($"ReadImageMatWithResizeSync: 不支持的插值算法 {interpolation}");
}
path = NormalizePath(path);
using var stream = File.OpenRead(path);
using var mat = Mat.FromStream(stream, ImreadModes.Color);
var rsz = new Mat();
Cv2.Resize(mat, rsz, new Size(width, height), 0, 0, (InterpolationFlags)interpolation);
return rsz;
}
catch (Exception ex)
{
// 记录异常并返回空的Mat
TaskControl.Logger.LogError("ReadImageMatWithResizeSync 异常: {Message}", ex.Message);
return new Mat();
}
}
View on GitHub (pinned to a7cb36712d)
Solutions
- Ensure the interpolation argument is an integer in the range 0–5 inclusive.
- If passing from JavaScript, validate the value before calling: if (interp < 0 || interp > 5) interp = 1;
- Check the XML doc comments above the method (lines 240–247) for the allowed values mapping.
Example fix
// before
dispatcher.readImageMatWithResizeSync('img.png', 1920, 1080, 7);
// after
dispatcher.readImageMatWithResizeSync('img.png', 1920, 1080, 1); // bilinear (default) Defensive patterns
Strategy: validation
Validate before calling
// Validate interpolation before calling
if (interpolation < 0 || interpolation > 5) {
interpolation = 1; // fallback to bilinear default
}
var mat = limitedFile.ReadImageMatWithResizeSync(path, width, height, interpolation); Try / catch
// Note: the method already catches internally and returns empty Mat.
// Check the result for emptiness:
var mat = limitedFile.ReadImageMatWithResizeSync(path, width, height, interpolation);
if (mat.Empty()) {
// handle failure - image was not loaded/resized
} Prevention
- Document the valid interpolation range (0–5) in your script's wrapper functions.
- Default to 1 (bilinear) when unsure which interpolation to use.
When it happens
Trigger: Calling ReadImageMatWithResizeSync(path, width, height, interpolation) with interpolation < 0 or > 5, e.g. passing 6, -1, or any value that does not map to a valid InterpolationFlags enum member. The default is 1 (bilinear).
Common situations: A JS script author passes a wrong interpolation constant (e.g. copies an OpenCV constant from documentation that is 0-based vs 1-based, or uses a value like 7). Mismatch between the script-side enum documentation and the actual 0–5 range.
Related errors
- 图像通道数必须为3,当前为{channels}
- ReadImageMatWithResizeSync: 宽度和高度必须为正数
- AutoSkip的配置参数需要为AutoSkipConfig类型
- 键盘编码必须是VirtualKeyCodes枚举中的值,当前传入的 {key} 不合法
- retryInterval 必须大于 0
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/62f169b873c815d6.
Report an issue: GitHub.