public void Render(IDrawingContextImpl context) { var finalRenderSurface = context.CreateLayer(_destRect.Size); if (finalRenderSurface is null) { context.Clear(Colors.Aqua); return; } using (var renderSurfaceCtx = finalRenderSurface.CreateDrawingContext(null)) { using (_lottieCanvas.CreateSession(_destRect.Size, finalRenderSurface, new DrawingContext(renderSurfaceCtx))) { _compositionLayer.Draw(_lottieCanvas, _matrix, 255); } } context.DrawBitmap(RefCountable.Create(finalRenderSurface), 1, new Rect(new Point(), finalRenderSurface.PixelSize.ToSize(1)), _destRect); finalRenderSurface.Dispose(); }
private void RenderComposite(Scene scene, ref IDrawingContextImpl context) { EnsureDrawingContext(ref context); context.Clear(Colors.Transparent); var clientRect = new Rect(scene.Size); var firstLayer = true; foreach (var layer in scene.Layers) { var bitmap = Layers[layer.LayerRoot].Bitmap; var sourceRect = new Rect(0, 0, bitmap.Item.PixelSize.Width, bitmap.Item.PixelSize.Height); if (layer.GeometryClip != null) { context.PushGeometryClip(layer.GeometryClip); } if (layer.OpacityMask == null) { if (firstLayer && bitmap.Item.CanBlit) { bitmap.Item.Blit(context); } else { context.DrawBitmap(bitmap, layer.Opacity, sourceRect, clientRect); } } else { context.DrawBitmap(bitmap, layer.OpacityMask, layer.OpacityMaskRect, sourceRect); } if (layer.GeometryClip != null) { context.PopGeometryClip(); } firstLayer = false; } if (_overlay != null) { var sourceRect = new Rect(0, 0, _overlay.Item.PixelSize.Width, _overlay.Item.PixelSize.Height); context.DrawBitmap(_overlay, 0.5, sourceRect, clientRect); } if (DrawFps) { RenderFps(context, clientRect, scene.Layers.Count); } }
public override void Render(IDrawingContextImpl context) { var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas; var surface = (context as ISkiaDrawingContextImpl)?.SkSurface; if (canvas == null | surface == null) { context.Clear(Colors.White); context.DrawText(new SolidColorBrush(Colors.Black), new Point(), NoSkia); } else { Surface = surface; var width = (int)Bounds.Width; var height = (int)Bounds.Height; var info = new SKImageInfo(width, height); using (SKPaint paint = new SKPaint()) { SKColor[] colors = { SKColors.White, HueColor.ToSKColor() }; SKPoint center = new SKPoint(info.Rect.MidX, info.Rect.MidY); paint.Shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(width, 0), colors, SKShaderTileMode.Repeat); var rect = SKRect.Create(width, height); canvas.DrawRect(rect, paint); } // Creates the black gradient effect (transparent to black) using (SKPaint paint = new SKPaint()) { SKColor[] colors = { SKColors.Transparent, SKColors.Black }; paint.Shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(0, height), colors, SKShaderTileMode.Repeat); var rect = SKRect.Create(width, height); canvas.DrawRect(rect, paint); } using (SKPaint paint = new SKPaint()) { paint.Shader = SKShader.CreateColor(StrokeColor.ToSKColor()); var rect = SKRect.Create(width, height); paint.Style = SKPaintStyle.Stroke; paint.StrokeWidth = StrokeWidth; canvas.DrawRect(rect, paint); } } }
private void RenderComposite(Scene scene, IDrawingContextImpl context) { context.Clear(Colors.Transparent); var clientRect = new Rect(scene.Size); foreach (var layer in scene.Layers) { var bitmap = Layers[layer.LayerRoot].Bitmap; var sourceRect = new Rect(0, 0, bitmap.Item.PixelWidth, bitmap.Item.PixelHeight); if (layer.GeometryClip != null) { context.PushGeometryClip(layer.GeometryClip); } if (layer.OpacityMask == null) { context.DrawImage(bitmap, layer.Opacity, sourceRect, clientRect); } else { context.DrawImage(bitmap, layer.OpacityMask, layer.OpacityMaskRect, sourceRect); } if (layer.GeometryClip != null) { context.PopGeometryClip(); } } if (_overlay != null) { var sourceRect = new Rect(0, 0, _overlay.Item.PixelWidth, _overlay.Item.PixelHeight); context.DrawImage(_overlay, 0.5, sourceRect, clientRect); } if (DrawFps) { RenderFps(context, clientRect, scene.Layers.Count); } }
public override void Render(IDrawingContextImpl context) { // converts the impl to SKCanvas var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas; //Checks if that is valid if (canvas == null) { context.Clear(Colors.White); context.DrawText(new SolidColorBrush(Colors.Black), new Point(), NoSkia); } else // when it's valid to this { var info = new SKImageInfo((int)Bounds.Width, (int)Bounds.Height); // creates the image info using (SKPaint paint = new SKPaint()) // creates the paint { // Define an array of rainbow colors SKColor[] colors = new SKColor[8]; for (int i = 0; i < colors.Length; i++) { colors[i] = SKColor.FromHsl(i * 360f / 7, 100, 50); //sets the colors } SKPoint center = new SKPoint(info.Rect.MidX, info.Rect.MidY); // creates the center // Create sweep gradient based on center of canvas paint.Shader = SKShader.CreateSweepGradient(center, colors, null); // Draw a circle with a wide line paint.Style = SKPaintStyle.Stroke; paint.StrokeWidth = StrokeWidth; float radius = (Math.Min(info.Width, info.Height) - StrokeWidth) / 2; //computes the radius canvas.DrawCircle(center, radius, paint); // draw a circle with its respects parameters } } }
public override void Render(IDrawingContextImpl context) { var canvas = ((ISkiaDrawingContextImpl)context)?.SkCanvas; if (canvas == null) { context.Clear(Colors.White); context.DrawText(new SolidColorBrush(Colors.Black), new Point(), NoSkia); } else { int width = (int)Bounds.Width; int height = (int)Bounds.Height; var info = new SKImageInfo(width, height); //canvas.Scale((float)Bounds.Width, (float)Bounds.Height, -(float)Bounds.Width, -(float)Bounds.Height); canvas.RotateDegrees(-90f, (float)Bounds.Center.X, (float)Bounds.Center.Y); using (SKPaint paint = new SKPaint()) { SKColor[] colors = new SKColor[8]; for (int i = 0; i < colors.Length; i++) { colors[i] = SKColor.FromHsl(i * 360f / 7, 100, 50); //sets the colors } SKPoint center = new SKPoint(info.Rect.MidX, info.Rect.MidY); // creates the center // Create sweep gradient based on center of canvas paint.Shader = SKShader.CreateSweepGradient(center, colors, null); float radius = (Math.Min(info.Width, info.Height) - StrokeWidth) / 2; //computes the radius canvas.DrawCircle(center, radius, paint); // draw a circle with its respects parameters } // Creates the black gradient effect (transparent to black) using (SKPaint paint = new SKPaint()) { SKColor[] colors = { SKColors.White, SKColors.Transparent }; SKPoint center = new SKPoint(info.Rect.MidX, info.Rect.MidY); // creates the center int strokeWidth = 20; float radius = (Math.Min(info.Width, info.Height) - strokeWidth) / 2; //computes the radius paint.Shader = SKShader.CreateRadialGradient(center, radius, colors, null, SKShaderTileMode.Repeat); canvas.DrawCircle(center, radius, paint); } using (SKPaint paint = new SKPaint()) { var colorStroke = Stroke.ToSKColor(); SKPoint center = new SKPoint(info.Rect.MidX, info.Rect.MidY); // creates the center float radius = (Math.Min(info.Width, info.Height) - StrokeWidth) / 2; //computes the radius paint.Shader = SKShader.CreateColor(colorStroke); paint.Style = SKPaintStyle.Stroke; paint.StrokeWidth = StrokeWidth; canvas.DrawCircle(center, radius, paint); } } }