Scale() public method

public Scale ( SKPoint size ) : void
size SKPoint
return void
Beispiel #1
0
        public static void RenderTexture(SKCanvas canvas, SKBitmap bitmap, float x, float y, float orientation = 0,
            float offsetX = 0, float offsetY = 0,
            LabelStyle.HorizontalAlignmentEnum horizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center,
            LabelStyle.VerticalAlignmentEnum verticalAlignment = LabelStyle.VerticalAlignmentEnum.Center,
            float opacity = 1f,
            float scale = 1f)
        {
            canvas.Save();

            canvas.Translate(x, y);
            canvas.RotateDegrees(orientation, 0, 0); // todo: or degrees?
            canvas.Scale(scale, scale);

            x = offsetX + DetermineHorizontalAlignmentCorrection(horizontalAlignment, bitmap.Width);
            y = -offsetY + DetermineVerticalAlignmentCorrection(verticalAlignment, bitmap.Height);

            var halfWidth = bitmap.Width/2;
            var halfHeight = bitmap.Height/2;

            var rect = new SKRect(x - halfWidth, y - halfHeight, x + halfWidth, y + halfHeight);

            RenderTexture(canvas, bitmap, rect, opacity);

            canvas.Restore();
        }
Beispiel #2
0
        public static void DrawGradient(SKCanvas canvas, int width, int height)
        {
            var ltColor = SKColors.White;
            var dkColor = SKColors.Black;

            using (var paint = new SKPaint()) {
                paint.IsAntialias = true;
                using (var shader = SKShader.CreateLinearGradient(
                           new SKPoint(0, 0),
                           new SKPoint(0, height),
                           new [] { ltColor, dkColor },
                           null,
                           SKShaderTileMode.Clamp)) {
                    paint.Shader = shader;
                    canvas.DrawPaint(paint);
                }
            }

            // Center and Scale the Surface
            var scale = (width < height ? width : height) / (240f);

            canvas.Translate(width / 2f, height / 2f);
            canvas.Scale(scale, scale);
            canvas.Translate(-128, -128);

            using (var paint = new SKPaint()) {
                paint.IsAntialias = true;
                using (var shader = SKShader.CreateTwoPointConicalGradient(
                           new SKPoint(115.2f, 102.4f),
                           25.6f,
                           new SKPoint(102.4f, 102.4f),
                           128.0f,
                           new [] { ltColor, dkColor },
                           null,
                           SKShaderTileMode.Clamp
                           )) {
                    paint.Shader = shader;

                    canvas.DrawOval(new SKRect(51.2f, 51.2f, 204.8f, 204.8f), paint);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Combines 2 images into one, given the shared ImageStats for both supplied images.
        /// </summary>
        /// <param name="info">the ImageStats object used to generate both bottom and top tiles.</param>
        /// <param name="bottomTile">the tile to use as the base of the image. Expected to be opaque.</param>
        /// <param name="topTile">The tile to layer on top. Expected to be at least partly transparent or translucent.</param>
        /// <returns></returns>
        public byte[] LayerTiles(ImageStats info, byte[] bottomTile, byte[] topTile)
        {
            SkiaSharp.SKBitmap bitmap = new SkiaSharp.SKBitmap(info.imageSizeX, info.imageSizeY, SkiaSharp.SKColorType.Rgba8888, SkiaSharp.SKAlphaType.Premul);
            SkiaSharp.SKCanvas canvas = new SkiaSharp.SKCanvas(bitmap);
            SkiaSharp.SKPaint  paint  = new SkiaSharp.SKPaint();
            canvas.Scale(1, 1, info.imageSizeX / 2, info.imageSizeY / 2);
            paint.IsAntialias = true;

            var baseBmp = SkiaSharp.SKBitmap.Decode(bottomTile);
            var topBmp  = SkiaSharp.SKBitmap.Decode(topTile);

            canvas.DrawBitmap(baseBmp, 0, 0);
            canvas.DrawBitmap(topBmp, 0, 0);
            var ms   = new MemoryStream();
            var skms = new SkiaSharp.SKManagedWStream(ms);

            bitmap.Encode(skms, SkiaSharp.SKEncodedImageFormat.Png, 100);
            var output = ms.ToArray();

            skms.Dispose(); ms.Close(); ms.Dispose();
            return(output);
        }
Beispiel #4
0
                #pragma warning restore 414

        public static void DrawXamagon(SKCanvas canvas, int width, int height)
        {
            // Width 41.6587026 => 144.34135
            // Height 56 => 147

            var paddingFactor = .6f;
            var imageLeft     = 41.6587026f;
            var imageRight    = 144.34135f;
            var imageTop      = 56f;
            var imageBottom   = 147f;

            var imageWidth = imageRight - imageLeft;

            var scale = (((float)height > width ? width : height) / imageWidth) * paddingFactor;

            var translateX = (imageLeft + imageRight) / -2 + width / scale * 1 / 2;
            var translateY = (imageBottom + imageTop) / -2 + height / scale * 1 / 2;

            canvas.Scale(scale, scale);
            canvas.Translate(translateX, translateY);


            using (var paint = new SKPaint()) {
                paint.IsAntialias = true;
                paint.Color       = SKColors.White;
                canvas.DrawPaint(paint);

                paint.StrokeCap = SKStrokeCap.Round;
                var t = paint.StrokeCap;


                using (var path = new SKPath()) {
                    path.MoveTo(71.4311121f, 56f);
                    path.CubicTo(68.6763107f, 56.0058575f, 65.9796704f, 57.5737917f, 64.5928855f, 59.965729f);
                    path.LineTo(43.0238921f, 97.5342563f);
                    path.CubicTo(41.6587026f, 99.9325978f, 41.6587026f, 103.067402f, 43.0238921f, 105.465744f);
                    path.LineTo(64.5928855f, 143.034271f);
                    path.CubicTo(65.9798162f, 145.426228f, 68.6763107f, 146.994582f, 71.4311121f, 147f);
                    path.LineTo(114.568946f, 147f);
                    path.CubicTo(117.323748f, 146.994143f, 120.020241f, 145.426228f, 121.407172f, 143.034271f);
                    path.LineTo(142.976161f, 105.465744f);
                    path.CubicTo(144.34135f, 103.067402f, 144.341209f, 99.9325978f, 142.976161f, 97.5342563f);
                    path.LineTo(121.407172f, 59.965729f);
                    path.CubicTo(120.020241f, 57.5737917f, 117.323748f, 56.0054182f, 114.568946f, 56f);
                    path.LineTo(71.4311121f, 56f);
                    path.Close();

                    paint.Color = XamDkBlue;
                    canvas.DrawPath(path, paint);
                }

                using (var path = new SKPath()) {
                    path.MoveTo(71.8225901f, 77.9780432f);
                    path.CubicTo(71.8818491f, 77.9721857f, 71.9440029f, 77.9721857f, 72.0034464f, 77.9780432f);
                    path.LineTo(79.444074f, 77.9780432f);
                    path.CubicTo(79.773437f, 77.9848769f, 80.0929203f, 78.1757336f, 80.2573978f, 78.4623994f);
                    path.LineTo(92.8795281f, 101.015639f);
                    path.CubicTo(92.9430615f, 101.127146f, 92.9839987f, 101.251384f, 92.9995323f, 101.378901f);
                    path.CubicTo(93.0150756f, 101.251354f, 93.055974f, 101.127107f, 93.1195365f, 101.015639f);
                    path.LineTo(105.711456f, 78.4623994f);
                    path.CubicTo(105.881153f, 78.167045f, 106.215602f, 77.975134f, 106.554853f, 77.9780432f);
                    path.LineTo(113.995483f, 77.9780432f);
                    path.CubicTo(114.654359f, 77.9839007f, 115.147775f, 78.8160066f, 114.839019f, 79.4008677f);
                    path.LineTo(102.518299f, 101.500005f);
                    path.LineTo(114.839019f, 123.568869f);
                    path.CubicTo(115.176999f, 124.157088f, 114.671442f, 125.027775f, 113.995483f, 125.021957f);
                    path.LineTo(106.554853f, 125.021957f);
                    path.CubicTo(106.209673f, 125.019028f, 105.873247f, 124.81384f, 105.711456f, 124.507327f);
                    path.LineTo(93.1195365f, 101.954088f);
                    path.CubicTo(93.0560031f, 101.84258f, 93.0150659f, 101.718333f, 92.9995323f, 101.590825f);
                    path.CubicTo(92.983989f, 101.718363f, 92.9430906f, 101.842629f, 92.8795281f, 101.954088f);
                    path.LineTo(80.2573978f, 124.507327f);
                    path.CubicTo(80.1004103f, 124.805171f, 79.7792269f, 125.008397f, 79.444074f, 125.021957f);
                    path.LineTo(72.0034464f, 125.021957f);
                    path.CubicTo(71.3274867f, 125.027814f, 70.8220664f, 124.157088f, 71.1600463f, 123.568869f);
                    path.LineTo(83.4807624f, 101.500005f);
                    path.LineTo(71.1600463f, 79.400867f);
                    path.CubicTo(70.8647037f, 78.86725f, 71.2250368f, 78.0919422f, 71.8225901f, 77.9780432f);
                    path.LineTo(71.8225901f, 77.9780432f);
                    path.Close();

                    paint.Color = SKColors.White;
                    canvas.DrawPath(path, paint);
                }
            }
        }
		#pragma warning restore 414

		public static void DrawXamagon (SKCanvas canvas, int width, int height)
		{
			// Width 41.6587026 => 144.34135
			// Height 56 => 147

			var paddingFactor = .6f;
			var imageLeft = 41.6587026f;
			var imageRight = 144.34135f;
			var imageTop = 56f;
			var imageBottom = 147f;

			var imageWidth = imageRight - imageLeft;

			var scale = (((float)height > width ? width : height) / imageWidth) * paddingFactor;

			var translateX =  (imageLeft + imageRight) / -2 + width/scale * 1/2;
			var translateY =  (imageBottom + imageTop) / -2 + height/scale * 1/2;

			canvas.Scale (scale, scale);
			canvas.Translate (translateX , translateY);


			using (var paint = new SKPaint ()) {
				paint.IsAntialias = true;
				paint.Color = SKColors.White;
				canvas.DrawPaint (paint);

				paint.StrokeCap = SKStrokeCap.Round;
				var t = paint.StrokeCap;


				using (var path = new SKPath ()) {
					path.MoveTo (71.4311121f, 56f);
					path.CubicTo (68.6763107f, 56.0058575f, 65.9796704f, 57.5737917f, 64.5928855f, 59.965729f);
					path.LineTo (43.0238921f, 97.5342563f);
					path.CubicTo (41.6587026f, 99.9325978f, 41.6587026f, 103.067402f, 43.0238921f, 105.465744f);
					path.LineTo (64.5928855f, 143.034271f);
					path.CubicTo (65.9798162f, 145.426228f, 68.6763107f, 146.994582f, 71.4311121f, 147f);
					path.LineTo (114.568946f, 147f);
					path.CubicTo (117.323748f, 146.994143f, 120.020241f, 145.426228f, 121.407172f, 143.034271f);
					path.LineTo (142.976161f, 105.465744f);
					path.CubicTo (144.34135f, 103.067402f, 144.341209f, 99.9325978f, 142.976161f, 97.5342563f);
					path.LineTo (121.407172f, 59.965729f);
					path.CubicTo (120.020241f, 57.5737917f, 117.323748f, 56.0054182f, 114.568946f, 56f);
					path.LineTo (71.4311121f, 56f);
					path.Close ();

					paint.Color = XamDkBlue;
					canvas.DrawPath (path, paint);

				}

				using (var path = new SKPath ()) {

					path.MoveTo (71.8225901f, 77.9780432f);
					path.CubicTo (71.8818491f, 77.9721857f, 71.9440029f, 77.9721857f, 72.0034464f, 77.9780432f);
					path.LineTo (79.444074f, 77.9780432f);
					path.CubicTo (79.773437f, 77.9848769f, 80.0929203f, 78.1757336f, 80.2573978f, 78.4623994f);
					path.LineTo (92.8795281f, 101.015639f);
					path.CubicTo (92.9430615f, 101.127146f, 92.9839987f, 101.251384f, 92.9995323f, 101.378901f);
					path.CubicTo (93.0150756f, 101.251354f, 93.055974f, 101.127107f, 93.1195365f, 101.015639f);
					path.LineTo (105.711456f, 78.4623994f);
					path.CubicTo (105.881153f, 78.167045f, 106.215602f, 77.975134f, 106.554853f, 77.9780432f);
					path.LineTo (113.995483f, 77.9780432f);
					path.CubicTo (114.654359f, 77.9839007f, 115.147775f, 78.8160066f, 114.839019f, 79.4008677f);
					path.LineTo (102.518299f, 101.500005f);
					path.LineTo (114.839019f, 123.568869f);
					path.CubicTo (115.176999f, 124.157088f, 114.671442f, 125.027775f, 113.995483f, 125.021957f);
					path.LineTo (106.554853f, 125.021957f);
					path.CubicTo (106.209673f, 125.019028f, 105.873247f, 124.81384f, 105.711456f, 124.507327f);
					path.LineTo (93.1195365f, 101.954088f);
					path.CubicTo (93.0560031f, 101.84258f, 93.0150659f, 101.718333f, 92.9995323f, 101.590825f);
					path.CubicTo (92.983989f, 101.718363f, 92.9430906f, 101.842629f, 92.8795281f, 101.954088f);
					path.LineTo (80.2573978f, 124.507327f);
					path.CubicTo (80.1004103f, 124.805171f, 79.7792269f, 125.008397f, 79.444074f, 125.021957f);
					path.LineTo (72.0034464f, 125.021957f);
					path.CubicTo (71.3274867f, 125.027814f, 70.8220664f, 124.157088f, 71.1600463f, 123.568869f);
					path.LineTo (83.4807624f, 101.500005f);
					path.LineTo (71.1600463f, 79.400867f);
					path.CubicTo (70.8647037f, 78.86725f, 71.2250368f, 78.0919422f, 71.8225901f, 77.9780432f);
					path.LineTo (71.8225901f, 77.9780432f);
					path.Close ();

					paint.Color = SKColors.White;
					canvas.DrawPath (path, paint);
				}
			}
		}
		public static void DrawGradient (SKCanvas canvas, int width, int height)
		{
			var ltColor = SKColors.White;
			var dkColor = SKColors.Black;

			using (var paint = new SKPaint ()) {
				paint.IsAntialias = true;
				using (var shader = SKShader.CreateLinearGradient (
					new SKPoint (0, 0),
					new SKPoint (0, height),
					new [] {ltColor, dkColor},
					null,
					SKShaderTileMode.Clamp)) {

					paint.Shader = shader;
					canvas.DrawPaint (paint);
				}
			}

			// Center and Scale the Surface
			var scale = (width < height ? width : height) / (240f);
			canvas.Translate (width/2f, height/2f);
			canvas.Scale (scale, scale);
			canvas.Translate (-128, -128);

			using (var paint = new SKPaint ()) {
				paint.IsAntialias = true;
				using (var shader = SKShader.CreateTwoPointConicalGradient (
					new SKPoint (115.2f, 102.4f), 
					25.6f,
					new SKPoint (102.4f, 102.4f),
					128.0f,
					new [] {ltColor, dkColor},
					null,
					SKShaderTileMode.Clamp
				)) {
					paint.Shader = shader;

					canvas.DrawOval (new SKRect (51.2f, 51.2f, 204.8f, 204.8f), paint);
				}
			}
		}
Beispiel #7
0
 private static void DrawPointWithSymbolStyle(SKCanvas canvas, SymbolStyle style,
     Point destination, SymbolType symbolType = SymbolType.Ellipse)
 {
     canvas.Save();
     canvas.Translate((float)destination.X,(float)destination.Y);
     canvas.Scale((float)style.SymbolScale, (float)style.SymbolScale);
     DrawPointWithVectorStyle(canvas, style, symbolType);
     canvas.Restore();
 }