how can I load an SVG Image by base64 bytes and place it on a Sprite Renderer

As the question states I have a byte array for an SVG image that I want to get onto a Sprite Renderer.
But I have had no luck achieving this so I’m hoping someone has something to point me in the right direction.

I tried something like this here how to set Image that converted from Base64 string to Sprite - Questions & Answers - Unity Discussions but this works only for png or jpg.

I also made sure the bytes were correct by using this converter to show my image Base64 to SVG | Image | Base64 Decode | Base64 Converter | Base64

the documentation here About Vector Graphics | Vector Graphics | 2.0.0-preview.21 is not very helpful for trying to figure this one out.

Any help on this would be greatly appreciated!

Have a look over here. I haven’t used any svg images in Unity yet, so i can not verify that it works.

edit

Here’s my test example using the Unity logo from wikipedia

using System.Collections.Generic;
using UnityEngine;
using Unity.VectorGraphics;
using System.IO;

public class SVGTest : MonoBehaviour
{
    public TextAsset svgAsset;
    public VectorUtils.TessellationOptions tesselationOptions;
    [SerializeField] private SpriteRenderer spriteRenderer;

    private void Start()
    {
        tesselationOptions.MaxCordDeviation = float.MaxValue;
        tesselationOptions.MaxTanAngleDeviation = float.MaxValue;
        tesselationOptions.StepDistance = 1f;
        tesselationOptions.SamplingStepSize = 0.1f;
        LoadSVG(svgAsset.text);
    }

    private void LoadSVG(string svgBytes)
    {
        using (StringReader reader = new StringReader(svgBytes))
        {
            SVGParser.SceneInfo sceneInfo = SVGParser.ImportSVG(reader);
            List<VectorUtils.Geometry> geoms = VectorUtils.TessellateScene(sceneInfo.Scene, tesselationOptions);

            // Build a sprite with the tessellated geometry.
            Sprite sprite = VectorUtils.BuildSprite(geoms, 100.0f, VectorUtils.Alignment.Center, Vector2.zero, 128, true);
            sprite.name = "SVGimage";
            spriteRenderer.sprite = sprite;
        }
    }
}

I renamed the svg file and appended .bytes so I was able to assign the file as text asset to my script. the image loaded well as expected.

Note that the image is not base64 encoded as it is just a plain svg image which is just plain XML text. You could use base64 encoding on top, but it would just make the file larger for no reason and requires you to decode it first before passing it to the svg parser.