Skip to content

StbSharp/StbImageResizeSharp

Repository files navigation

StbImageResizeSharp

NuGet Build & Publish Chat

StbImageResizeSharp is C# port of the stb_image_resize.h, which is C library to resize images.

Adding Reference

There are two ways of referencing StbImageResizeSharp in the project:

  1. Through nuget: https://www.nuget.org/packages/StbImageResizeSharp/

  2. As submodule:

    a. git submodule add https://github.com/rds1983/StbImageResizeSharp.git

    b. Now there are two options:

    • Add src/StbImageResizeSharp.csproj to the solution

    • Include *.cs from folder "src" directly in the project. In this case, it might make sense to add STBSHARP_INTERNAL build compilation symbol to the project, so StbImageResizeSharp classes would become internal.

Usage

StbImageResizeSharp exposes API similar to stb_image_resize.h. Also it adds some wrapper methods.

Sample code to load and resize an image

    // Load an image using StbImageSharp(https://github.com/StbSharp/StbImageSharp)
    ImageResult image;
    using(var stream = File.OpenRead("image.png"))
    {
      image = ImageResult.FromStream(stream);
    }
    
    // Retrieve amount of channels in the image(from 1 to 4)
    int channels = (int)image.Comp;

    // Resize to 400x400
    int newWidth = 400;
    int newHeight = 400;
    byte[] newImageData = new byte[newWidth * newHeight * channels];
    StbImageResize.stbir_resize_uint8(imageData, width, height, image.Width * channels,
        newImageData, newWidth, newHeight, newWidth * channels, channels);

License

Public Domain

Credits

https://github.com/nothings/stb

About

C# port of stb_image_resize.h

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages