请问是否有可能使用C#将Bitmap
转换为WebP
图像?
我已经在Google上搜索过,但没有找到适用于C#的解决方案。我找到了这个链接:mc-kay/libwebp-sharp · GitHub,但它似乎不能将位图转换为WebP
格式。
有什么建议吗?
请问是否有可能使用C#将Bitmap
转换为WebP
图像?
我已经在Google上搜索过,但没有找到适用于C#的解决方案。我找到了这个链接:mc-kay/libwebp-sharp · GitHub,但它似乎不能将位图转换为WebP
格式。
有什么建议吗?
加载WebP图像
using (Bitmap image = WebPFormat.LoadFromStream(new FileStream("image.webp", FileMode.Open, FileAccess.Read)))
{
image.Save("image.png", ImageFormat.Png);
}
保存WebP图片
using (Image image = Image.FromFile("image.jpg"))
{
Bitmap bitmap = new Bitmap(image);
WebPFormat.SaveToFile("image.webp", bitmap);
}
想了解更多信息,请查看 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
}