Skip to content

Decodes an image and converts Texture2D on Unity with pure C#.

License

Notifications You must be signed in to change notification settings

mochi-neko/StbImageSharpForUnity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StbImageSharpForUnity

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).

How to import by UPM

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.

How to use

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.

Support Codecs

  • JPG
  • PNG
  • BMP
  • TGA
  • PSD
  • GIF
  • (HDR)

See also StbImageSharp.

Support Platforms

All platforms supported by Unity are supported because StbImageSharp is written by pure C#.

See also StbImageSharp.

Changelog

See CHANGELOG.md.

Credits

See also NOTICE.md.

License

MIT License

About

Decodes an image and converts Texture2D on Unity with pure C#.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages