ImageConversion

unityengine.ImageConversion (extern class)

Utility class for converting between Texture2D and image file formats. Enables loading images from bytes and saving textures to common formats.

In Ceramic's Unity backend, this is used for:

  • Dynamic texture loading from downloaded data
  • Screenshot/capture functionality
  • Runtime texture import/export
  • Converting between formats

Supported formats:

  • PNG: Lossless, supports transparency
  • JPG: Lossy compression, no transparency
  • EXR: High dynamic range (32-bit float)
  • TGA: Uncompressed with alpha

Static Members

unity
EncodeToPNG(tex: Texture2D): haxe.io.BytesData

Encodes a Texture2D to PNG format bytes.

Name Type Description
tex Texture2D Source texture (must be readable)
Returns Description
haxe.io.BytesData PNG file data as bytes, or null if encoding fails * Features: - Lossless compression - Preserves alpha channel - Smaller file size than TGA - Wide compatibility * Saving a texture: haxe var pngData = ImageConversion.EncodeToPNG(myTexture); File.saveBytes("screenshot.png", Bytes.ofData(pngData)); * Note: Texture must have Read/Write enabled in import settings.

unity
EncodeToJPG(tex: Texture2D, quality: Int): haxe.io.BytesData

Encodes a Texture2D to JPEG format with specified quality.

Name Type Description
tex Texture2D Source texture (must be readable)
quality Int JPEG compression quality (1-100): 1 = Lowest quality, smallest file 75 = Good balance (recommended) 100 = Highest quality, largest file
Returns Description
haxe.io.BytesData JPEG file data as bytes, or null if encoding fails * Features: - Lossy compression (smaller files) - No alpha channel support - Good for photos/complex images * Note: Alpha channel is converted to black. Use PNG for images requiring transparency.

unity
LoadImage(tex: Texture2D, data: haxe.io.BytesData, markNonReadable: Bool): Bool

Loads image data into an existing Texture2D. Automatically detects format (PNG, JPG, etc.).

Name Type Description
tex Texture2D Target texture (will be resized to match image)
data haxe.io.BytesData Image file bytes (PNG, JPG, etc.)
markNonReadable Bool If true, marks texture as non-readable after loading (saves memory)
Returns Description
Bool True if loading succeeded, false otherwise * Loading downloaded image: haxe var texture = new Texture2D(2, 2); // Size will be replaced if (ImageConversion.LoadImage(texture, imageBytes, false)) { // Texture now contains the image } * Supported formats: PNG, JPG, TGA, BMP, GIF, and more. Format detected automatically from file data.

Metadata

Name Parameters
:nativeGen -