CSharpMath icon indicating copy to clipboard operation
CSharpMath copied to clipboard

Fatal example for CSharpMath.SkiaSharp

Open harveytriana opened this issue 1 year ago • 2 comments

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);
}

harveytriana avatar Sep 04 '23 16:09 harveytriana

Where does the PictureBox come from?

Happypig375 avatar Sep 04 '23 16:09 Happypig375

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.

harveytriana avatar Sep 04 '23 21:09 harveytriana