CSharpMath
CSharpMath copied to clipboard
Fatal example for CSharpMath.SkiaSharp
The Example2. CSharpMath.SkiaSharp, apart from having syntax errors, doesn't say anything. Suggest to replace it with the following.
using CSharpMath.SkiaSharp;
using SkiaSharp;
//...
void DrawSample()
{
var p = pictureBox; // exists a PictureBox with name pictureBox
// create canvas
var imageInfo = new SKImageInfo(p.Width, p.Height);
using var surface = SKSurface.Create(imageInfo);
using var canvas = surface.Canvas;
var painter = new MathPainter {
LaTeX = @"\frac\sqrt23"
};
painter.Draw(canvas);
using var snapshot = surface.Snapshot();
using var image = snapshot.Encode(SKEncodedImageFormat.Png, 100);
using var stream = new MemoryStream(image.ToArray());
p.Image = new Bitmap(stream, false);
}
Where does the PictureBox come from?
It is a WinForm Control, in this case a project net7.0-windows. I publish that: https://github.com/harveytriana/LaTeXForms
Of course, the canvas can be from SKCanvasView for other platforms. i.g. Blazor or MAUI.