Lens Scripting API

    Class Base64

    Handles encoding and decoding images and textures into Base64 format, commonly used to embed images in JSON or other text-based formats.

    //@input Asset.Texture texture
    //@input Component.Image outputImage

    function printEncodedString(result) {
    print("Encoded texture: " + result)
    //decode the string back and display
    decode(result).then(displayTexture).catch(printError)
    }

    function printError(error) {
    print("Error: " + error)

    }

    function displayTexture(texture) {
    print("Texture: " + texture)
    if (script.outputImage) {
    script.outputImage.mainMaterial.mainPass.baseTex = texture
    }
    }

    function encode(texture) {
    return new Promise(function (resolve, reject) {
    Base64.encodeTextureAsync(texture, resolve, reject, CompressionQuality.LowQuality, EncodingType.Png)
    })
    }

    function decode(encodedString) {
    return new Promise(function (resolve, reject) {
    Base64.decodeTextureAsync(encodedString, resolve, reject)
    })
    }

    encode(script.texture).then(printEncodedString).catch(printError);
    Index

    Constructors

    Methods

    • Parameters

      • value: string

      Returns Uint8Array

    • Decode a texture from Base64, asynchronously.

      Parameters

      • value: string
      • onSuccess: (decodedTexture: Texture) => void
      • onFailure: () => void

      Returns void

    • Parameters

      • data: Uint8Array

      Returns string

    • Encode a texture according to Base64 encoding algorithm, asynchronously.

      Parameters

      Returns void

    MMNEPVFCICPMFPCPTTAAATR