Forwarding a C# library that draws on a SKCanvas (Skia)

Hello all!

I’m trying to forward the NuGet CSharpMath to VL. The goal is to take a LaTeX expression and render it into a Skia Layer, so (for now), it should be one input (string) and one output (Layer). Later I’d like to add some more functionality similar to the Text node.

The API from CSharpMath is relatively simple, essentially already taking a string and drawing into onto a SkiaSharp SKContext. Here’s a basic example:

var painter = new MathPainter { LaTeX = tex };
var bmp = new SKBitmap(500, 500);
var canvas = new SKCanvas(bmp);
painter.Draw(canvas, new SKPoint(0, 0));

I was able to create this sketch (Download) which simply creates a new MathPainter instance and sets it’s LaTeX attribute, but I am stuck trying to draw on a SKCanvas, since the Draw function requires a SKCanvas as input:

In the Matrix Chat I was advised to use the SkiaLayer region, which would apparently give me a Skia Context to draw on but I was not able to find any docs on this, or find the region inside my vvvv editor (VL.Skia is added as a dependency).

I’d also probably only want to redraw the output layer if the input changed, since the function is deterministic, but that’s very low priority.

Can anyone give me some pointers on how to properly forward this library?
Thanks for your help!

– FritzFurtz

Attached you find a patch where you can interact with the SKCanvas. It makes use of an (on purpose) undocumented feature, you’ll find a little explanation on in the patch.

HowTo Draw With SKCanvas.vl (6.3 KB)

4 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.