.NET bindings for libwebp. Provides WebP encoding and decoding via both System.Drawing (Bitmap) and raw pixel buffer APIs. Requires a platform-specific Imazen.WebP.NativeRuntime package or Imazen.WebP.AllPlatforms.
$ dotnet add package Imazen.WebPEncode, decode, and animate WebP images from .NET. Supports both System.Drawing.Bitmap and raw pixel buffer APIs for cross-platform use.
WebPEncoder, WebPDecoder) work everywhere without System.Drawingwin-x64, win-x86, win-arm64, linux-x64, linux-arm64, osx-x64, osx-arm64net472, net48, netstandard2.0, and net8.0WebPEncoderConfig builder for quality, method, lossless presets, near-lossless, alpha quality, sharp YUV, and moreWebPInfo retrieves dimensions, alpha, animation, and format without full decodingdotnet add package Imazen.WebP.AllPlatforms
Or install only the runtime you need (see Packages below).
using Imazen.WebP;
var encoder = new SimpleEncoder();
using var bitmap = new Bitmap("input.png");
using var stream = File.Create("output.webp");
// Lossy encoding (quality 0–100), or -1 for lossless
encoder.Encode(bitmap, stream, 80);
using Imazen.WebP;
var decoder = new SimpleDecoder();
byte[] webpBytes = File.ReadAllBytes("image.webp");
using Bitmap bitmap = decoder.DecodeFromBytes(webpBytes, webpBytes.LongLength);
using Imazen.WebP;
byte[] webpBytes = File.ReadAllBytes("image.webp");
byte[] pixels = WebPDecoder.Decode(webpBytes, out int width, out int height, WebPPixelFormat.Rgba);
// pixels is now width * height * 4 bytes of RGBA data
using Imazen.WebP;
byte[] encoded = WebPEncoder.Encode(rgbaPixels, width, height, width * 4, WebPPixelFormat.Rgba, quality: 80);
File.WriteAllBytes("output.webp", encoded);
using Imazen.WebP;
var config = new WebPEncoderConfig()
.SetQuality(85)
.SetMethod(6) // Slowest, best compression
.SetSharpYuv() // Better color fidelity
.SetSnsStrength(50)
.SetFilterStrength(20);
var encoder = new SimpleEncoder();
using var bitmap = new Bitmap("input.png");
using var stream = File.Create("output.webp");
encoder.Encode(bitmap, stream, config);
using Imazen.WebP;
byte[] animatedWebP = File.ReadAllBytes("animation.webp");
using var decoder = new AnimDecoder(animatedWebP);
Console.WriteLine($"{decoder.Info.FrameCount} frames, {decoder.Info.Width}x{decoder.Info.Height}");
foreach (var frame in decoder.DecodeAllFrames())
{
// frame.Pixels = BGRA byte array for the full canvas
// frame.TimestampMs, frame.DurationMs
}
using Imazen.WebP;
using var encoder = new AnimEncoder(width, height, loopCount: 0);
encoder.AddFrame(frame1Bgra, timestampMs: 0, quality: 80);
encoder.AddFrame(frame2Bgra, timestampMs: 100, quality: 80);
encoder.AddFrame(frame3Bgra, timestampMs: 200, quality: 80);
byte[] animatedWebP = encoder.Assemble();
File.WriteAllBytes("animation.webp", animatedWebP);
using Imazen.WebP;
byte[] data = File.ReadAllBytes("image.webp");
var info = WebPInfo.GetImageInfo(data);
Console.WriteLine($"{info.Width}x{info.Height}, alpha={info.HasAlpha}, animated={info.HasAnimation}");
| Package | Description |
|---|---|
Imazen.WebP | Managed bindings (requires a runtime package) |
Imazen.WebP.AllPlatforms | Managed bindings + all 7 native runtimes |
Imazen.WebP.NativeRuntime.win-x64 | Windows x64 native libraries |
Imazen.WebP.NativeRuntime.win-x86 | Windows x86 native libraries |
Imazen.WebP.NativeRuntime.win-arm64 | Windows ARM64 native libraries |
Imazen.WebP.NativeRuntime.linux-x64 | Linux x64 native libraries |
Imazen.WebP.NativeRuntime.linux-arm64 | Linux ARM64 native libraries |
Imazen.WebP.NativeRuntime.osx-x64 | macOS x64 native libraries |
Imazen.WebP.NativeRuntime.osx-arm64 | macOS ARM64 (Apple Silicon) native libraries |
| OS | Architecture | .NET Framework 4.7.2+ | .NET Standard 2.0 | .NET 8+ |
|---|---|---|---|---|
| Windows | x64 | Yes | Yes | Yes |
| Windows | x86 | Yes | Yes | Yes |
| Windows | ARM64 | Yes (.NET 4.8.1+) | Yes | Yes |
| Linux | x64 | — | Yes | Yes |
| Linux | ARM64 | — | Yes | Yes |
| macOS | x64 | — | Yes | Yes |
| macOS | ARM64 | — | Yes | Yes |
Full API documentation is available at imazen.github.io/libwebp-net.
MIT — Copyright 2012–2026 Imazen LLC