Skip to content

Sharp0802/WebP.Net

Repository files navigation

WebP.Net

What is this?

This library provides a simple encoder and decoder for webp.

How to use?

Install

In your csproj :

<PackageReference Include="WebP_Net" Version="1.1.1" />

Or, if you using .net cli :

dotnet add package WebP_Net --version 1.1.1

Encode / Decode

using System.Drawing;
using WebP.Net;

static byte[] EncodeLossy(Bitmap bitmap, float quality)
{
    using var webp = new WebPObject(bitmap);
    return webp.GetWebPLossy(quality);
}
static byte[] EncodeLossless(Bitmap bitmap)
{
    using var webp = new WebPObject(bitmap);
    return webp.GetLossless();
}
static Image DecodeWebP(byte[] webP)
{
    using var webp = new WebPObject(webP);
    return webp.GetImage();
}

Get info

using WebP.Net;

static WebPInfo GetInfo(byte[] webP)
{
    using var webp = new WebPObject(webP);
    return webP.GetInfo();
}

Get version

using WebP.Net;

static WebPVersion GetVersion()
{
    return WebPObject.GetVersion(); // get version of libwebp
}
static string GetVersionAsString()
{
    return WebPObject.GetVersion().ToString(); // Major.Minor.Revision
}