Joey Morani
Joey Morani

Reputation: 26581

Convert Bitmap to WebP Image?

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

Answers (1)

Quan Truong
Quan Truong

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

Related Questions