Provides an Unity extension of StbImageSharp.
Decodes a binary image file byte[]
or Stream
and converts to Texture2D on Unity with pure C# (without any native libraries).
Add
dependencies: {
"com.stbsharp.stbimagesharp": "https://github.com/mochi-neko/StbImageSharpForUnity.git?path=/Assets/StbImageSharp",
"com.mochineko.stbimagesharp-for-unity": "https://github.com/mochi-neko/StbImageSharpForUnity.git?path=/Assets/Mochineko/StbImageSharpForUnity",
}
to /Packages/manifest.json
on your Unity project and add its reference to your Assembly Definition.
Also you can add a demo codes by adding
"com.mochineko.stbimagesharp-for-unity.demo": "https://github.com/mochi-neko/StbImageSharpForUnity.git?path=/Assets/Mochineko/StbImageSharpForUnity.Demo",
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask",
to your dependencies.
A sample usage with the UniTask is as follows:
private async UniTask<Texture2D> LoadImageAsync(byte[] data)
{
await UniTask.SwitchToThreadPool();
// Decodes an image on a thread pool.
var imageResult = ImageDecoder.DecodeImage(data);
await UniTask.SwitchToMainThread();
// Creates a texture and set the pixel data on the main thread.
return imageResult.ToTexture2D();
}
.
See also Demo.
For animated GIF images, see Animated GIF Demo.
- JPG
- PNG
- BMP
- TGA
- PSD
- GIF
- (HDR)
See also StbImageSharp.
All platforms supported by Unity are supported because StbImageSharp is written by pure C#.
See also StbImageSharp.
See CHANGELOG.md.
See also NOTICE.md.