Skip to main content
Version: 21 Aug 2024

MLTextureUtils

NameSpace: Native

Class containing utility functions to convert Unity Texture to Magic Leap OS compatible data structures.

Public Methods

byte [] ConvertToByteArray

Convert Unity Texture2D to a byte array. Texture2D should be in one of the following formats: DXT1, RGBA32, RGB24. For DXT1 and RGBA32, resulting byte array is in RGBA format. For RGB24, resulting byte array is in RGB format. The origin of the byte array will be at the top left corner. Returns null on unsupported formats.

public static byte [] ConvertToByteArray(
Texture2D texture,
out int numChannels
)

Parameters

TypeNameDescription
Texture2DtextureTexture to extract byte array from
out intnumChannelsOut parameter to determine how many bytes per pixel

Returns: Returns an array of bytes that holds the converted texture


byte [] FlipPixelsVertically

Performs a vertical flip on a byte array of image pixel data. Each pixel is assumed to be 4 bytes.

public static byte [] FlipPixelsVertically(
byte [] originalPixels,
int width,
int height
)

Parameters

TypeNameDescription
byte []originalPixelsThe pixels array of the image to be flipped. The array length is assumed to be 4 * width * height.
intwidthThe number of the pixels wide of the image from the data.
intheightThe number of the pixels high of the image from the data.

Returns: A new byte array arranged vertically flipped from the input array of pixels.