d2phap/ImageGlass · error · Exception
This DLL version not support EncodeNearLossless
Error message
This DLL version not support EncodeNearLossless
What it means
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.
Source
Thrown at v9/Components/ImageGlass.WebP/WebPWrapper.cs:574
config.pass = speed + 1;
config.thread_level = 1;
config.alpha_filtering = 2;
config.use_sharp_yuv = 1;
config.exact = 0;
return AdvancedEncode(bmp, config, false);
}
/// <summary>Near lossless encoding image in bitmap</summary>
/// <param name="bmp">Bitmap with the image</param>
/// <param name="quality">Between 0 (lower quality, lowest file size) and 100 (highest quality, higher file size)</param>
/// <param name="speed">Between 0 (fastest, lowest compression) and 9 (slower, best compression)</param>
/// <returns>Compress data</returns>
public byte[] EncodeNearLossless(Bitmap bmp, int quality, int speed = 9)
{
//test DLL version
if (LibWebp.WebPGetDecoderVersion() <= 1082)
throw new Exception("This DLL version not support EncodeNearLossless");
//Inicialize config struct
WebPConfig config = new WebPConfig();
//Set compression parameters
if (LibWebp.WebPConfigInit(ref config, WebPPreset.WEBP_PRESET_DEFAULT, (speed + 1) * 10) == 0)
throw new Exception("Can't configure preset");
if (LibWebp.WebPConfigLosslessPreset(ref config, speed) == 0)
throw new Exception("Can't configure lossless preset");
config.pass = speed + 1;
config.near_lossless = quality;
config.thread_level = 1;
config.alpha_filtering = 2;
config.use_sharp_yuv = 1;
config.exact = 0;
return AdvancedEncode(bmp, config, false);
}View on GitHub (pinned to 4a3c4fecef)
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.
Example fix
// before
var bytes = webp.EncodeNearLossless(bmp, quality, speed);
// after
if (LibWebp.WebPGetDecoderVersion() <= 1082)
bytes = webp.EncodeLossless(bmp, speed);
else
bytes = webp.EncodeNearLossless(bmp, quality, speed); Defensive patterns
Strategy: type-guard
Validate before calling
bool supportsNearLossless = LibWebp.WebPGetDecoderVersion() > 1082;
var bytes = supportsNearLossless
? webp.EncodeNearLossless(bmp, quality, speed)
: webp.EncodeLossless(bmp, speed); Type guard
static bool SupportsNearLossless() => LibWebp.WebPGetDecoderVersion() > 1082;
Try / catch
try { var bytes = webp.EncodeNearLossless(bmp, quality, speed); }
catch (Exception ex) when (ex.Message.Contains("not support EncodeNearLossless"))
{ var bytes = webp.EncodeLossless(bmp, speed); } Prevention
- 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.
When it happens
Trigger: Calling EncodeNearLossless(bmp, quality, speed) while the loaded libwebp reports a version number <= 1082 (older libwebp).
Common situations: Shipping an old libwebp.dll; a system where an outdated libwebp is on the path; a third-party app embedding a legacy build.
Related errors
- Can't configure preset
- Can't config preset
- Can't configure lossless preset
- Bad configuration parameters
- Can't initialize WebPPictureInit
AI-assisted analysis of d2phap/ImageGlass@4a3c4fecef (2026-08-13).
Data as JSON: /api/errors/f29d7a8c8e3b30b3.
Report an issue: GitHub.