コード例 #1
0
        private static void DrawCompare(this SKCanvas canvas, SKImageInfo info, CelestialDrawModel origin, CelestialDrawModel compare)
        {
            var originRadius    = origin.Radius;
            var compareRadius   = compare.Radius;
            var maxCanvasWidth  = info.Width;
            var maxCanvasHeight = info.Height;
            var maxRadius       = DoubleHelper.GetMax(originRadius, compareRadius);
            var minRadius       = DoubleHelper.GetMin(originRadius, compareRadius);

            var divisionFactor = maxCanvasWidth * 0.9 / (minRadius * 4 > maxRadius ? 2 : 1);

            var factor = maxRadius / divisionFactor;

            var originFactoredRadius  = (int)DoubleHelper.GetMax(Math.Floor(originRadius / factor), 1);
            var compareFactoredRadius = (int)DoubleHelper.GetMax(Math.Floor(compareRadius / factor), 1);

            var originCentreX  = GetCentreX(maxCanvasWidth, originFactoredRadius, true);
            var compareCentreX = GetCentreX(maxCanvasWidth, compareFactoredRadius, false);

            var centreY = maxCanvasHeight / 2;

            var originDraw  = new CanvasDrawModel(origin.Id, origin.Description, originFactoredRadius, originCentreX, centreY, origin.Color, null, null, 0);
            var compareDraw = new CanvasDrawModel(compare.Id, compare.Description, compareFactoredRadius, compareCentreX, centreY, compare.Color, null, null, 0);

            canvas.Draw(originDraw);
            canvas.Draw(compareDraw);
        }
コード例 #2
0
        /// <summary>
        /// Draw strokes
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="strokes"></param>
        public static void Draw(this SKCanvas canvas, IEnumerable <XInkStroke> strokes)
        {
            if (strokes == null)
            {
                return;
            }

            foreach (var stroke in strokes)
            {
                canvas.Draw(stroke, true);
            }
        }
コード例 #3
0
        /// <summary>
        /// Draw the ink strokes that are within the bounds
        /// </summary>
        /// <param name="canvas">the SkiaSharp canvas</param>
        /// <param name="strokes">the candidate strokes</param>
        /// <param name="bounds">the bounds to draw in</param>
        public static void Draw(this SKCanvas canvas, IEnumerable <XInkStroke> strokes, SKRect bounds)
        {
            if (strokes == null)
            {
                return;
            }

            foreach (var stroke in strokes)
            {
                if (!bounds.IntersectsWith(stroke.BoundingRect.ToSKRect()))
                {
                    continue;
                }

                canvas.Draw(stroke, true);
            }
        }
コード例 #4
0
        private static void DrawOrbits(this SKCanvas canvas, IEnumerable <CelestialDrawModel> orbits, DrawParameterModel drawParameters)
        {
            foreach (var orbit in orbits.Where(x => x.Radius > 0))
            {
                var draw =
                    new CanvasDrawModel(
                        orbit.Id,
                        orbit.Description,
                        (int)Math.Ceiling(orbit.Radius * drawParameters.OrbitFactor) + SunRadius,
                        drawParameters.CentreX,
                        drawParameters.CentreY,
                        null,
                        orbit.BorderColor,
                        null,
                        orbit.StrokeWidth);

                canvas.Draw(draw);
            }
        }
コード例 #5
0
        private static void DrawBodies(this SKCanvas canvas, IEnumerable <CelestialDrawModel> bodies, DrawParameterModel drawParameters)
        {
            var orderedBodies = bodies.OrderByDescending(x => x.Radius).ToList();
            var sizes         = new[] { SunRadius, 20, 18, 16, 14, 8, 8, 6, 4, 4 };

            for (var index = 0; index < orderedBodies.Count; index++)
            {
                try
                {
                    var body = orderedBodies[index];

                    var centreX = GetCentreValue(drawParameters.CentreX, body.Location, DrawOrientation.Vertical, drawParameters);
                    var centreY = GetCentreValue(drawParameters.CentreY, body.Location, DrawOrientation.Horizontal, drawParameters);

                    var draw =
                        new CanvasDrawModel(
                            body.Id,
                            body.Description,
                            sizes[index],
                            centreX,
                            centreY,
                            body.Color,
                            null,
                            null,
                            0);

                    canvas.Draw(draw);
                }
                catch (ArgumentException exception)
                {
                    LogHelper.LogError(exception);
                }
                catch (Exception exception)
                {
                    LogHelper.LogError(exception);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// render an image of ink strokes
        /// </summary>
        /// <param name="width">the width of the image</param>
        /// <param name="height">the height of the image</param>
        /// <param name="backgroundColor">the background color</param>
        /// <param name="strokes">the strokes</param>
        /// <param name="stream">the image stream to write to</param>
        /// <param name="scaledWidth">the scaled width</param>
        public static void RenderImage(int width, int height, Color backgroundColor, IReadOnlyList <XInkStroke> strokes, Stream stream, int scaledWidth)
        {
            if (strokes == null)
            {
                throw new ArgumentNullException(nameof(strokes));
            }

            var scale = Convert.ToDouble(scaledWidth) / Convert.ToDouble(width);

            var bitmapWidth = Convert.ToDouble(width) * scale;

            var bitmapHeight = Convert.ToDouble(height) * scale;

            using var bitmap = new SKBitmap(Convert.ToInt32(bitmapWidth), Convert.ToInt32(bitmapHeight));
            using (var canvas = new SKCanvas(bitmap))
            {
                DrawBackground(backgroundColor, canvas, new SKRect(0, 0, width, height));

                canvas.Scale(Convert.ToSingle(scale), Convert.ToSingle(scale), 0, 0);

                foreach (var stroke in strokes)
                {
                    canvas.Draw(stroke, true);
                }
            }

            using var image = SKImage.FromBitmap(bitmap);
            using var data  = image.Encode(SKEncodedImageFormat.Jpeg, 100);
            data.SaveTo(stream);

            //using (var wStream = new SKManagedWStream(stream))
            //{
            //	var pixels = bitmap.PeekPixels();

            //	SKPixmap.Encode(wStream, pixels, SKJpegEncoderOptions.Default);
            //}
        }