{"record":{"id":"62f169b873c815d6","repo":"babalae/better-genshin-impact","slug":"readimagematwithresizesync-interpolatio","errorCode":null,"errorMessage":"ReadImageMatWithResizeSync: 不支持的插值算法 {interpolation}","messagePattern":"ReadImageMatWithResizeSync: 不支持的插值算法 (.+?)","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"BetterGenshinImpact/Core/Script/Dependence/LimitedFile.cs","lineNumber":260,"sourceCode":"    /// <item><description>双线性插值 (1) - 默认</description></item>\n    /// <item><description>双三次插值 (2)</description></item>\n    /// <item><description>像素区域关系重采样 (3)</description></item>\n    /// <item><description>Lanczos插值 (4)</description></item>\n    /// <item><description>精确双线性插值 (5)</description></item>\n    /// </list>\n    /// </remarks>\n    public Mat ReadImageMatWithResizeSync(string path, double width, double height, int interpolation = 1)\n    {\n        try\n        {\n            if (width <= 0 || height <= 0)\n            {\n                throw new Exception(\"ReadImageMatWithResizeSync: 宽度和高度必须为正数\");\n            }\n\n            if (interpolation is < 0 or > 5)\n            {\n                throw new Exception($\"ReadImageMatWithResizeSync: 不支持的插值算法 {interpolation}\");\n            }\n\n            path = NormalizePath(path);\n            using var stream = File.OpenRead(path);\n            using var mat = Mat.FromStream(stream, ImreadModes.Color);\n            var rsz = new Mat();\n            Cv2.Resize(mat, rsz, new Size(width, height), 0, 0, (InterpolationFlags)interpolation);\n            return rsz;\n        }\n        catch (Exception ex)\n        {\n            // 记录异常并返回空的Mat\n            TaskControl.Logger.LogError(\"ReadImageMatWithResizeSync 异常: {Message}\", ex.Message);\n            return new Mat();\n        }\n    }\n\n    ","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Script/Dependence/LimitedFile.cs#L242-L278","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\ndispatcher.readImageMatWithResizeSync('img.png', 1920, 1080, 7);\n// after\ndispatcher.readImageMatWithResizeSync('img.png', 1920, 1080, 1); // bilinear (default)","handlingStrategy":"validation","validationCode":"// Validate interpolation before calling\nif (interpolation < 0 || interpolation > 5) {\n    interpolation = 1; // fallback to bilinear default\n}\nvar mat = limitedFile.ReadImageMatWithResizeSync(path, width, height, interpolation);","typeGuard":null,"tryCatchPattern":"// Note: the method already catches internally and returns empty Mat.\n// Check the result for emptiness:\nvar mat = limitedFile.ReadImageMatWithResizeSync(path, width, height, interpolation);\nif (mat.Empty()) {\n    // handle failure - image was not loaded/resized\n}","preventionTips":["Document the valid interpolation range (0–5) in your script's wrapper functions.","Default to 1 (bilinear) when unsure which interpolation to use."],"tags":["opencv","image-processing","argument-validation","script-api"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}