Convert Bitmap to WebP Image?
Asked Answered
S

1

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?

Statuary answered 4/11, 2012 at 16:27 Comment(0)
N
-1

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 !

Nuli answered 2/8, 2023 at 2:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.