Class ImageUtils
A utility class to assist with loading images into the game. Useful for icons such as on phone apps, custom NPCs, quests, etc. This class is intended for public use by mod developers.
public static class ImageUtils
- Inheritance
-
ImageUtils
- Inherited Members
Methods
LoadImage(string)
Loads an image from the specified file path and converts it into a Sprite object.
public static Sprite? LoadImage(string fileName)
Parameters
fileNamestringThe name of the file (with path) containing the image to load.
Returns
- Sprite
A Sprite object representing the loaded image, or null if the image could not be loaded or the file does not exist.
LoadImageFromResource(Assembly, string, float, FilterMode)
Loads an image from an embedded resource stream and converts it into a Sprite object.
public static Sprite? LoadImageFromResource(Assembly assembly, string resourceName, float pixelsPerUnit = 100, FilterMode filterMode = 1)
Parameters
assemblyAssemblyThe assembly containing the embedded resource.
resourceNamestringThe fully qualified name of the embedded resource (e.g., "Namespace.Assets.Icon.png").
pixelsPerUnitfloatThe pixels per unit for the sprite. Defaults to 100f.
filterModeFilterModeThe filter mode for the texture. Defaults to FilterMode.Bilinear.
Returns
- Sprite
A Sprite object representing the loaded image, or null if the resource could not be found or loaded.
LoadImageRaw(byte[])
Loads an image from a byte array and converts it into a Sprite object.
public static Sprite? LoadImageRaw(byte[] data)
Parameters
databyte[]The byte array containing the image data to load.
Returns
- Sprite
A Sprite object representing the loaded image, or null if the image could not be loaded.
TextureToSprite(Texture2D?, float)
Converts a Texture2D to a Sprite.
public static Sprite? TextureToSprite(Texture2D? texture, float pixelsPerUnit = 100)
Parameters
textureTexture2DThe texture to convert.
pixelsPerUnitfloatThe pixels per unit for the sprite. Defaults to 100f.
Returns
- Sprite
A Sprite object, or null if texture is null.