/// <summary> /// Write a directed graph to an image using SkiaSharp. /// </summary> /// <param name="graph">The directed graph.</param> /// <param name="width">Desired width of the image.</param> /// <param name="height">Desired height of the image.</param> /// <returns></returns> private Image WriteToImage(DirectedGraph graph, int width, int height) { using (SkiaContext context = new SkiaContext((int)width, (int)height)) { DirectedGraphRenderer.Draw(context, graph); return(context.Save()); } }
/// <summary>The drawing canvas is being exposed to user.</summary> private void OnDrawingAreaExpose(object sender, DrawnArgs args) { try { DrawingArea area = (DrawingArea)sender; Cairo.Context context = args.Cr; CairoContext drawingContext = new CairoContext(context, MainWidget); DirectedGraphRenderer.Draw(drawingContext, arcs, nodes); ((IDisposable)context.GetTarget()).Dispose(); ((IDisposable)context).Dispose(); } catch (Exception err) { ShowError(err); } }
/// <summary>The drawing canvas is being exposed to user.</summary> private void OnDrawingAreaExpose(object sender, DrawnArgs args) { try { DrawingArea area = (DrawingArea)sender; Cairo.Context context = args.Cr; DGObject.DefaultOutlineColour = area.StyleContext.GetColor(StateFlags.Normal).ToColour(); #pragma warning disable 0612 DGObject.DefaultBackgroundColour = area.StyleContext.GetBackgroundColor(StateFlags.Normal).ToColour(); #pragma warning restore 0612 CairoContext drawingContext = new CairoContext(context, MainWidget); DirectedGraphRenderer.Draw(drawingContext, arcs, nodes); ((IDisposable)context.GetTarget()).Dispose(); ((IDisposable)context).Dispose(); } catch (Exception err) { ShowError(err); } }