Skip to content

Tom94/stbi-sharp

Repository files navigation

StbiSharp

A C# wrapper around the single-header image-loading libraries stb_image.h and qoi.h. It supports JPEG, PNG, QOI, BMP, GIF, HDR, PIC, PNM, PSD, and TGA (for some formats only a subset of features; consult stb_image.h for details).

Usage

Grab StbiSharp from nuget, then load an image as follows:

public void doSomethingWithImage()
{
    using (var stream = File.OpenRead("some-image.jpg"))
    using (var memoryStream = new MemoryStream())
    {
        stream.CopyTo(memoryStream);
        StbiImage image = Stbi.LoadFromMemory(memoryStream, 4);

        // Use image.Width, image.Height,
        // image.NumChannels, and image.Data.
    }
}

If the encoded image is directly available in memory, no file stream needs to be used.

Building

You are only required to build StbiSharp if you plan to develop it further or fix bugs. In case this applies to you, thank you for helping out! :)

Rather than explaining in text how to build StbiSharp, I invite you to check our GitHub build-and-publish workflow. It contains the minimal set of instructions to build the native STBI lib via a C++ compiler on Ubuntu, macOS, and Windows, as well as the minimal set of instructions for building the C# wrapper using dotnet.

License

StbiSharp is available under the BSD 3-clause license, which you can find in the LICENSE.txt file. TL;DR you can do almost whatever you want as long as you include the original copyright and license notice in any copy of the software and the source code.