4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

C# でWebPを読み書きする

Posted at

画像処理などで使う画像をWebPに変換して容量減らせればいいなーと思ってやり方を調べたので
備忘録的に書いておきます。

Nugetで「ImageProcessor」パッケージをインストールする

Visual Studio 2022 .Net Framework 4.8で動作を確認しています。
他の環境は未チェックですのであしからず。

image.png

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);
    }
}
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?