private void ApplyTransform(ITransform transform, IXGraphics xGraphics) { if (transform is IRotateTransform rotateTransform) { skCanvas.RotateDegrees((float)rotateTransform.Angle, (float)rotateTransform.CenterX, (float)rotateTransform.CenterY); } else if (transform is IScaleTransform scaleTransform) { skCanvas.Scale((float)scaleTransform.ScaleX, (float)scaleTransform.ScaleY, (float)scaleTransform.CenterX, (float)scaleTransform.CenterY); } else if (transform is ITranslateTransform translateTransform) { skCanvas.Translate((float)translateTransform.X, (float)translateTransform.Y); } else if (transform is ITransformGroup transformGroup) { foreach (ITransform childTransform in transformGroup.Children) { ApplyTransform(childTransform, xGraphics); } } else { throw new InvalidOperationException($"Unknown transform type {transform.GetType()}"); } }
public override void RenderToBuffer(IXGraphics xGraphics, IntPtr pixels, int width, int height, int rowBytes) { var info = new SKImageInfo(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul); using (SKSurface surface = SKSurface.Create(info, pixels, rowBytes)) { // Paint all elements from the canvas on the surface new SkiaPainter(surface).Paint(xGraphics); } }
public void Paint(IXGraphics xGraphics) { IBrush?background = xGraphics.Background; if (background is ISolidColorBrush solidColorBrush) { skCanvas.Clear(ToSkiaColor(solidColorBrush.Color)); } else { skCanvas.Clear(SKColors.Transparent); } ITransform?xGraphicsRenderTransform = xGraphics.GraphicsRenderTransform; if (xGraphicsRenderTransform != null) { ApplyTransform(xGraphicsRenderTransform, xGraphics); } foreach (IGraphicsElement graphicsElement in xGraphics.Children) { ITransform?renderTransform = graphicsElement.RenderTransform; if (renderTransform != null) { skCanvas.Save(); ApplyTransform(renderTransform, graphicsElement); } if (graphicsElement is IPath path) { PaintPath(path); } else if (graphicsElement is IShape shape) { SKPath skiaPath = NonPathShapeToSkiaPath(shape); PaintSkiaPath(skiaPath, shape); } else { throw new InvalidOperationException($"Unknown graphics element type {graphicsElement.GetType()}"); } if (renderTransform != null) { skCanvas.Restore(); } } }
/// <summary> /// Render the graphics to the specified bitmap memory buffer. /// </summary> /// <param name="xGraphics">graphics object to render</param> /// <param name="pixels">buffer data</param> /// <param name="width">width of the bitmap, in pixels</param> /// <param name="height">height of the bitmap, in pixels</param> /// <param name="rowBytes">number of bytes per row in the buffer</param> public abstract void RenderToBuffer(IXGraphics xGraphics, IntPtr pixels, int width, int height, int rowBytes);