protected override void OnResultadoPaintSurface(SKSurface s, SKImageInfo i) { base.OnResultadoPaintSurface(s, i); if (ViewModel == null) { return; } var p = new MathPainter(12) { TextColor = SKColors.White }; p.LaTeX = (Result) ? @"\text{Es un número primo}" : @"\text{No es un número primo}"; var pM = p.Measure; if (pM.HasValue) { Resultado.WidthRequest = pM.Value.Width; Resultado.HeightRequest = pM.Value.Height; } p.Draw(s.Canvas, alignment: CSharpMath.Rendering.TextAlignment.Left); }
public Stream Render(string latex) { var painter = new MathPainter { LaTeX = latex }; var path = Path.GetTempFileName(); var measures = painter.Measure(); SKBitmap bitMap = new SKBitmap( width: ((int)measures.Width) + 2 * LatexBorder, height: ((int)measures.Height) + 2 * LatexBorder ); var canvas = new SKCanvas(bitMap); painter.Draw( canvas: canvas, point: new SKPoint(LatexBorder, (measures.Height / 2.0f) + LatexBorder) ); canvas.Flush(); using (var image = SKImage.FromBitmap(bitMap)) using (var data = image.Encode(SKEncodedImageFormat.Png, 100)) { // save the data to a stream using var streamf = File.OpenWrite(path); data.SaveTo(streamf); } return(File.Open(path, FileMode.Open)); }
virtual protected void OnEnunciadoPaintSurface(SKSurface s, SKImageInfo i) { s.Canvas.Clear(SKColors.Green); if (ViewModel == null) { return; } var p = new MathPainter(12) { TextColor = SKColors.White }; p.LaTeX = $@"\text{{{ViewModel?.Numero}. {EnunciadoStr}}}"; var pM = p.Measure; if (pM.HasValue) { Enunciado.WidthRequest = pM.Value.Width; Enunciado.HeightRequest = pM.Value.Height; } p.Draw(s.Canvas, alignment: CSharpMath.Rendering.TextAlignment.Left); }