{"record":{"id":"f29d7a8c8e3b30b3","repo":"d2phap/ImageGlass","slug":"this-dll-version-not-support-encodenearlossless","errorCode":null,"errorMessage":"This DLL version not support EncodeNearLossless","messagePattern":"This DLL version not support EncodeNearLossless","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"v9/Components/ImageGlass.WebP/WebPWrapper.cs","lineNumber":574,"sourceCode":"        config.pass = speed + 1;\n        config.thread_level = 1;\n        config.alpha_filtering = 2;\n        config.use_sharp_yuv = 1;\n        config.exact = 0;\n\n        return AdvancedEncode(bmp, config, false);\n    }\n\n    /// <summary>Near lossless encoding image in bitmap</summary>\n    /// <param name=\"bmp\">Bitmap with the image</param>\n    /// <param name=\"quality\">Between 0 (lower quality, lowest file size) and 100 (highest quality, higher file size)</param>\n    /// <param name=\"speed\">Between 0 (fastest, lowest compression) and 9 (slower, best compression)</param>\n    /// <returns>Compress data</returns>\n    public byte[] EncodeNearLossless(Bitmap bmp, int quality, int speed = 9)\n    {\n        //test DLL version\n        if (LibWebp.WebPGetDecoderVersion() <= 1082)\n            throw new Exception(\"This DLL version not support EncodeNearLossless\");\n\n        //Inicialize config struct\n        WebPConfig config = new WebPConfig();\n\n        //Set compression parameters\n        if (LibWebp.WebPConfigInit(ref config, WebPPreset.WEBP_PRESET_DEFAULT, (speed + 1) * 10) == 0)\n            throw new Exception(\"Can't configure preset\");\n        if (LibWebp.WebPConfigLosslessPreset(ref config, speed) == 0)\n            throw new Exception(\"Can't configure lossless preset\");\n        config.pass = speed + 1;\n        config.near_lossless = quality;\n        config.thread_level = 1;\n        config.alpha_filtering = 2;\n        config.use_sharp_yuv = 1;\n        config.exact = 0;\n\n        return AdvancedEncode(bmp, config, false);\n    }","sourceCodeStart":556,"sourceCodeEnd":592,"githubUrl":"https://github.com/d2phap/ImageGlass/blob/4a3c4feceffc5a8bb5e56ba836509634aaae47a9/v9/Components/ImageGlass.WebP/WebPWrapper.cs#L556-L592","documentation":"Thrown by EncodeNearLossless when LibWebp.WebPGetDecoderVersion() returns <= 1082. Near-lossless encoding was added to libwebp after version 0.1.0.3 (1082), so older binaries simply do not expose the required functions. The wrapper refuses to proceed rather than calling a missing P/Invoke.","triggerScenarios":"Calling EncodeNearLossless(bmp, quality, speed) while the loaded libwebp reports a version number <= 1082 (older libwebp).","commonSituations":"Shipping an old libwebp.dll; a system where an outdated libwebp is on the path; a third-party app embedding a legacy build.","solutions":["Update the bundled libwebp to a recent build (>= 0.1.0.4 / 1083+) that supports near-lossless encoding.","Check WebPWrapper.GetVersion() at startup and disable the near-lossless code path if the version is too old.","Fall back to EncodeLossless(bmp, speed) when near-lossless is unavailable."],"exampleFix":"// before\nvar bytes = webp.EncodeNearLossless(bmp, quality, speed);\n\n// after\nif (LibWebp.WebPGetDecoderVersion() <= 1082)\n    bytes = webp.EncodeLossless(bmp, speed);\nelse\n    bytes = webp.EncodeNearLossless(bmp, quality, speed);","handlingStrategy":"type-guard","validationCode":"bool supportsNearLossless = LibWebp.WebPGetDecoderVersion() > 1082;\nvar bytes = supportsNearLossless\n    ? webp.EncodeNearLossless(bmp, quality, speed)\n    : webp.EncodeLossless(bmp, speed);","typeGuard":"static bool SupportsNearLossless() => LibWebp.WebPGetDecoderVersion() > 1082;","tryCatchPattern":"try { var bytes = webp.EncodeNearLossless(bmp, quality, speed); }\ncatch (Exception ex) when (ex.Message.Contains(\"not support EncodeNearLossless\"))\n{ var bytes = webp.EncodeLossless(bmp, speed); }","preventionTips":["Gating on DLL version at startup avoids the runtime exception entirely.","Keep libwebp current to access newer encode modes.","Provide a documented fallback when the host's libwebp is too old."],"tags":["webp","encoding","near-lossless","version-gate","native-abi"],"backgroundTag":null,"analyzedSha":"4a3c4feceffc5a8bb5e56ba836509634aaae47a9","analyzedAt":"2026-08-13T16:58:15.523Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}