5

Anyone know if it's possible to convert a Bitmap to a WebP image using C#?

Been Google-ing around but wasn't able to find anything for C#. I found this: mc-kay/libwebp-sharp ยท GitHub but it doesn't seem to convert bitmaps to the WebP format.

Any ideas?

Picrofo Software
  • 5,475
  • 3
  • 23
  • 37
Joey Morani
  • 25,431
  • 32
  • 84
  • 131

1 Answers1

0

Download libwebp dll here. (There are 32-bit and 64-bit formats). Copy dll file to your bin folder (in local path and release folder)

Then, in your project, install Imazen.WebP

Code snippet :

using Imazen.WebP;

string folderPath = "C:/MyImages";
string webpFileName = "image123.webp";
Bitmap mBitmap = new Bitmap(img);

using (var saveImageStream = File.Open(folderPath + webpFileName, FileMode.Create)) 
{
    var encoder = new SimpleEncoder();
    encoder.Encode(mBitmap, saveImageStream, 75); // 75 is Image quality
}

Hope this help !

Quan Truong
  • 193
  • 4
  • 11