Reputation: 26581
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?
Upvotes: 5
Views: 14198
Reputation: 341
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 !
Upvotes: -1