Webp-Wrapper-for-NET-Win-x64
1.0.7
dotnet add package Webp-Wrapper-for-NET-Win-x64 --version 1.0.7
NuGet\Install-Package Webp-Wrapper-for-NET-Win-x64 -Version 1.0.7
<PackageReference Include="Webp-Wrapper-for-NET-Win-x64" Version="1.0.7" />
<PackageVersion Include="Webp-Wrapper-for-NET-Win-x64" Version="1.0.7" />
<PackageReference Include="Webp-Wrapper-for-NET-Win-x64" />
paket add Webp-Wrapper-for-NET-Win-x64 --version 1.0.7
#r "nuget: Webp-Wrapper-for-NET-Win-x64, 1.0.7"
#:package Webp-Wrapper-for-NET-Win-x64@1.0.7
#addin nuget:?package=Webp-Wrapper-for-NET-Win-x64&version=1.0.7
#tool nuget:?package=Webp-Wrapper-for-NET-Win-x64&version=1.0.7
This fork is intended for current versions of .NET. Includes the latest version of the library libwebp.dll v1.5.0. The structures have been updated to match the current version of the library.
The wrapper work only 64 bit system.
Package | Download |
---|---|
Webp-Wrapper-for-NET-Win-x64 |
dotnet add package Webp-Wrapper-for-NET-Win-x64
WebP-wrapper
Wrapper for libwebp in C#. The most complete wrapper in pure managed C#.
Exposes Simple Decoding and Encoding API, Advanced Decoding and Encoding API (with statistics of compression), Get version library and WebPGetFeatures (info of any WebP file). Exposed get PSNR, SSIM or LSIM distortion metrics.
The wrapper is in safe managed code in one class. No need for external dll except libwebp_x64.dll (included). The wrapper works in 64 bit.
The code is commented and includes simple examples for using the wrapper.
Decompress Functions:
Load WebP image for WebP file
using (WebP webp = new WebP())
Bitmap bmp = webp.Load("test.webp");
Decode WebP filename to bitmap and load in PictureBox container
byte[] rawWebP = File.ReadAllBytes("test.webp");
using (WebP webp = new WebP())
this.pictureBox.Image = webp.Decode(rawWebP);
Advanced decode WebP filename to bitmap and load in PictureBox container
byte[] rawWebP = File.ReadAllBytes("test.webp");
WebPDecoderOptions decoderOptions = new WebPDecoderOptions();
decoderOptions.use_threads = 1; //Use multhreading
decoderOptions.flip = 1; //Flip the image
using (WebP webp = new WebP())
this.pictureBox.Image = webp.Decode(rawWebP, decoderOptions);
Get thumbnail with 200x150 pixels in fast/low quality mode
using (WebP webp = new WebP())
this.pictureBox.Image = webp.GetThumbnailFast(rawWebP, 200, 150);
Get thumbnail with 200x150 pixels in slow/high quality mode
using (WebP webp = new WebP())
this.pictureBox.Image = webp.GetThumbnailQuality(rawWebP, 200, 150);
Compress Functions:
Save bitmap to WebP file
Bitmap bmp = new Bitmap("test.jpg");
using (WebP webp = new WebP())
webp.Save(bmp, 80, "test.webp");
Encode to memory buffer in lossy mode with quality 75 and save to file
byte[] rawWebP = File.ReadAllBytes("test.jpg");
using (WebP webp = new WebP())
rawWebP = webp.EncodeLossy(bmp, 75);
File.WriteAllBytes("test.webp", rawWebP);
Encode to memory buffer in lossy mode with quality 75 and speed 9. Save to file
byte[] rawWebP = File.ReadAllBytes("test.jpg");
using (WebP webp = new WebP())
rawWebP = webp.EncodeLossy(bmp, 75, 9);
File.WriteAllBytes("test.webp", rawWebP);
Encode to memory buffer in lossy mode with quality 75, speed 9 and get information. Save to file
byte[] rawWebP = File.ReadAllBytes("test.jpg");
using (WebP webp = new WebP())
rawWebP = webp.EncodeLossy(bmp, 75, 9, true);
File.WriteAllBytes("test.webp", rawWebP);
Encode to memory buffer in lossless mode and save to file
byte[] rawWebP = File.ReadAllBytes("test.jpg");
using (WebP webp = new WebP())
rawWebP = webp.EncodeLossless(bmp);
File.WriteAllBytes("test.webp", rawWebP);
Encode to memory buffer in lossless mode with speed 9 and save to file
byte[] rawWebP = File.ReadAllBytes("test.jpg");
using (WebP webp = new WebP())
rawWebP = webp.EncodeLossless(bmp, 9);
File.WriteAllBytes("test.webp", rawWebP);
Encode to memory buffer in near lossless mode with quality 40 and speed 9 and save to file
byte[] rawWebP = File.ReadAllBytes("test.jpg");
using (WebP webp = new WebP())
rawWebP = webp.EncodeNearLossless(bmp, 40, 9);
File.WriteAllBytes("test.webp", rawWebP);
Another Functions:
Get version of libwebp.dll
using (WebP webp = new WebP())
string version = "libwebp.dll v" + webp.GetVersion();
Get info from WebP file
byte[] rawWebp = File.ReadAllBytes(pathFileName);
using (WebP webp = new WebP())
webp.GetInfo(rawWebp, out width, out height, out has_alpha, out has_animation, out format);
MessageBox.Show("Width: " + width + "\n" +
"Height: " + height + "\n" +
"Has alpha: " + has_alpha + "\n" +
"Is animation: " + has_animation + "\n" +
"Format: " + format);
Get PSNR, SSIM or LSIM distortion metric between two pictures
int metric = 0; //0 = PSNR, 1= SSIM, 2=LSIM
Bitmap bmp1 = Bitmap.FromFile("image1.png");
Bitmap bmp2 = Bitmap.FromFile("image2.png");
using (WebP webp = new WebP())
result = webp.GetPictureDistortion(source, reference, metric);
MessageBox.Show("Red: " + result[0] + "dB.\nGreen: " + result[1] + "dB.\nBlue: " + result[2] + "dB.\nAlpha: " + result[3] + "dB.\nAll: " + result[4] + "dB.", "PSNR");
MessageBox.Show("Red: " + result[0] + dB\n" +
"Green: " + result[1] + "dB\n" +
"Blue: " + result[2] + "dB\n" +
"Alpha: " + result[3] + "dB\n" +
"All: " + result[4] + "dB\n");
Thanks to jzern@google.com
Without their help this wapper would not have been possible.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- System.Drawing.Common (>= 9.0.6)
-
net9.0
- System.Drawing.Common (>= 9.0.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
1.0.7: Performance optimization
1.0.6: .NET 9.0, .NET 8.0, libwebp.dll v1.5.0
1.0.5: .NET 9.0, libwebp.dll v1.5.0