コード例 #1
0
        void OnCanvasViewPaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs args)
        {
            SkiaSharp.SKImageInfo info    = args.Info;
            SkiaSharp.SKSurface   surface = args.Surface;
            SkiaSharp.SKCanvas    canvas  = surface.Canvas;
            canvas.Clear();
            SkiaSharp.SKRect bounds;
            SkiaSharp.SKPath path = SkiaSharp.SKPath.ParseSvgPathData((string)this.Resources["PathString"]);
            path.GetTightBounds(out bounds);
            SkiaSharp.SKPaint paint = new SkiaSharp.SKPaint
            {
                Style       = SkiaSharp.SKPaintStyle.Stroke,
                Color       = SkiaSharp.SKColors.Black,
                StrokeWidth = 10,
                StrokeCap   = SkiaSharp.SKStrokeCap.Round,
                StrokeJoin  = SkiaSharp.SKStrokeJoin.Round
            };
            canvas.Translate(info.Width / 2, info.Height / 2);

            canvas.Scale(info.Width / (bounds.Width + paint.StrokeWidth),
                         info.Height / (bounds.Height + paint.StrokeWidth));

            canvas.Translate(-bounds.MidX, -bounds.MidY);

            canvas.DrawPath(path, paint);
        }
コード例 #2
0
        /// <summary>
        /// Konvertiert die Farbe in den Lab-Farbraum.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>

        public static void Save(this SkiaSharp.SKSurface surf, string filename)
        {
            using (var image = surf.Snapshot().Encode())
            {
                using (var stream = File.OpenWrite(filename))
                {
                    image.SaveTo(stream);
                }
            }
        }
コード例 #3
0
        public void Redraw(SkiaSharp.SKSurface surface)
        {
            for (var i = 0; i < ElementController.LogicalChildren.Count; i++)
            {
                var child = ElementController.LogicalChildren[i] as VisualElement;
                if (child != null)
                {
                    OnChildRedraw(child, surface);

                    // update logical children
                    var viewRenderer = DoodlePlatform.GetDoodleRenderer(child);
                    viewRenderer.Packager.Redraw(surface);
                }
            }
        }
コード例 #4
0
 public SKPaintSurfaceEventArgs(SkiaSharp.SKSurface surface, SkiaSharp.SKImageInfo info)
 {
     Surface = surface;
     Info    = info;
 }
コード例 #5
0
        public void DrawSurface(CGContext ctx, CGRect viewBounds, SkiaSharp.SKImageInfo info, SkiaSharp.SKSurface surface)
        {
            if (info.Width == 0 || info.Height == 0)
            {
                return;
            }

            surface.Canvas.Flush();

            // draw the image onto the context
            using (var colorSpace = CGColorSpace.CreateDeviceRGB())
                using (var image = new CGImage(info.Width, info.Height, BitsPerByte, info.BytesPerPixel * BitsPerByte, info.RowBytes, colorSpace, BitmapFlags, dataProvider, null, false, CGColorRenderingIntent.Default))
                {
#if __IOS__ || __TVOS__ || __WATCHOS__ || HAS_UNO
                    // we need to flip the image as we are mixing CoreGraphics and UIKit functions:
                    // https://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GraphicsDrawingOverview/GraphicsDrawingOverview.html#//apple_ref/doc/uid/TP40010156-CH14-SW26
                    ctx.SaveState();
                    ctx.TranslateCTM(0, viewBounds.Height);
                    ctx.ScaleCTM(1, -1);
                    // draw the image
                    ctx.DrawImage(viewBounds, image);
                    ctx.RestoreState();
#elif __MACOS__
                    // draw the image
                    ctx.DrawImage(viewBounds, image);
#else
#error Plaform-specific code missing
#endif
                }
        }
コード例 #6
0
        protected virtual void OnChildRedraw(VisualElement view, SkiaSharp.SKSurface surface)
        {
            var viewRenderer = DoodlePlatform.GetDoodleRenderer(view);

            viewRenderer.DrawView(surface);
        }