Skip to content

Repository files navigation

StbImageResizeSharp

NuGetBuild & PublishChat

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)ImageResultimage;using(varstream=File.OpenRead("image.png")){image=ImageResult.FromStream(stream);}// Retrieve amount of channels in the image(from 1 to 4)intchannels=(int)image.Comp;// Resize to 400x400intnewWidth=400;intnewHeight=400;byte[]newImageData=newbyte[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

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages