有人知道是否可以使用 C# 将
Bitmap
转换为 WebP
图像?
Google 搜索过,但没有找到任何关于 C# 的内容。我找到了这个: mc-kay/libwebp-sharp · GitHub 但它似乎没有将位图转换为
WebP
格式。
有什么想法吗?
在此处下载 libwebp dll。 (有 32 位和 64 位格式)。将 dll 文件复制到您的 bin 文件夹(在本地路径和发布文件夹中)
然后,在您的项目中安装Imazen.WebP
代码片段:
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
}
希望这有帮助!