C# でWebPを読み書きする
画像処理などで使う画像をWebPに変換して容量減らせればいいなーと思ってやり方を調べたので
備忘録的に書いておきます。
Nugetで「ImageProcessor」パッケージをインストールする
Visual Studio 2022 .Net Framework 4.8で動作を確認しています。
他の環境は未チェックですのであしからず。
WebPから、jpegやpng等に変換して保存する
public static void Save(string inPutPath, string outPutPath, ImageFormat format)
{
var wf = new WebPFormat();
using (var image = (Bitmap)wf.Load(new FileStream(inPutPath, FileMode.Open, FileAccess.Read)))
{
image.Save(outPutPath, format);
}
}
jpegやpng等から、WebPに変換して保存する
Taskで並列に変換&保存できてるっぽいけど、すぐにCPU使用率が100%になる…
public static void SaveWebP(string inPutPath, string outPutPath)
{
var wf = new WebPFormat();
using (var image = new Bitmap(inPutPath))
{
wf.Save(outPutPath, image, 0);
}
}
Author And Source
この問題について(C# でWebPを読み書きする), 我々は、より多くの情報をここで見つけました https://qiita.com/visyeii/items/9320b0d08e6b132c6541著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .