当前位置: 首页>>代码示例>>C#>>正文


C# Canvas.DrawPath方法代码示例

本文整理汇总了C#中Android.Graphics.Canvas.DrawPath方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.DrawPath方法的具体用法?C# Canvas.DrawPath怎么用?C# Canvas.DrawPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Android.Graphics.Canvas的用法示例。


在下文中一共展示了Canvas.DrawPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawChild

        protected override bool DrawChild(Canvas canvas, View child, long drawingTime)
        {
            try
            {

                var radius = Math.Min(Width, Height) / 2;

                var borderThickness = (float)((CircleImage)Element).BorderThickness;

                int strokeWidth = 0;

                if (borderThickness > 0)
                {
                    var logicalDensity = Xamarin.Forms.Forms.Context.Resources.DisplayMetrics.Density;
                    strokeWidth = (int)Math.Ceiling(borderThickness * logicalDensity + .5f);
                }

                radius -= strokeWidth / 2;

                var path = new Path();
                path.AddCircle(Width / 2.0f, Height / 2.0f, radius, Path.Direction.Ccw);

                canvas.Save();
                canvas.ClipPath(path);

                var paint = new Paint();
                paint.AntiAlias = true;
                paint.SetStyle(Paint.Style.Fill);
                paint.Color = ((CircleImage)Element).FillColor.ToAndroid();
                canvas.DrawPath(path, paint);
                paint.Dispose();

                var result = base.DrawChild(canvas, child, drawingTime);

                canvas.Restore();

                path = new Path();
                path.AddCircle((float) Width / 2, (float) Height / 2, radius, Path.Direction.Ccw);

                if (strokeWidth > 0.0f)
                {
                    paint = new Paint {AntiAlias = true, StrokeWidth = strokeWidth};
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = ((CircleImage)Element).BorderColor.ToAndroid();
                    canvas.DrawPath(path, paint);
                    paint.Dispose();
                }

                path.Dispose();
                return result;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }

            return base.DrawChild(canvas, child, drawingTime);
        }
开发者ID:onikiri2007,项目名称:TestApp,代码行数:58,代码来源:CircleImageRenderer.cs

示例2: DrawShape

 protected void DrawShape(Canvas canvas)
 {
   Paint paint = new Paint();
   paint.Color = Color;
   switch (Shape)
   {
     case ShapeEnum.RectangleShape:
       canvas.DrawRect(0, 0, ShapeWidth, ShapeHeight, paint);
       break;
     case ShapeEnum.OvalShape:
       canvas.DrawOval(new RectF(0, 0, ShapeWidth, ShapeHeight), paint);
       break;
     case ShapeEnum.TriangleShape:
         Path path = new Path();
         path.MoveTo(ShapeWidth / 2, 0);
         path.LineTo(ShapeWidth, ShapeHeight);
         path.LineTo(0,ShapeHeight);
         path.Close();
       canvas.DrawPath(path, paint);
       break;
     default:
       canvas.DrawCircle(ShapeWidth / 2, ShapeHeight / 2, ShapeWidth / 2, paint); 
       break;
   }
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:25,代码来源:ShapeView.cs

示例3: OnDraw

		protected override void OnDraw (Canvas canvas)
		{
			
			drawCanvas = canvas;
			canvas.DrawBitmap(canvasBitmap, 0, 0, canvasPaint);
			canvas.DrawPath(drawPath, drawPaint);
		}
开发者ID:CrossGeeks,项目名称:Xamarin.Samples,代码行数:7,代码来源:NativeDrawView.cs

示例4: OnDraw

		protected override void OnDraw (Canvas canvas)
		{
			if (this.currentPath == null || this.currentPath.IsEmpty)
				return;

			canvas.DrawPath (this.currentPath, this.currentPaint);
		}
开发者ID:ronrat,项目名称:SignaturePad,代码行数:7,代码来源:SignatureCanvasView.cs

示例5: DrawChild

 protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
 {
     try
     {
         var radius = Math.Min(Width, Height) / 2;
         var strokeWidth = 10;
         radius -= strokeWidth / 2;
         //Create path to clip
         var path = new Path();
         path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
         canvas.Save();
         canvas.ClipPath(path);
         var result = base.DrawChild(canvas, child, drawingTime);
         canvas.Restore();
         // Create path for circle border
         path = new Path();
         path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
         var paint = new Paint();
         paint.AntiAlias = true;
         paint.StrokeWidth = 5;
         paint.SetStyle(Paint.Style.Stroke);
         paint.Color = global::Android.Graphics.Color.White;
         canvas.DrawPath(path, paint);
         //Properly dispose
         paint.Dispose();
         path.Dispose();
         return result;
     }
     catch (Exception ex)
     {
         Console.WriteLine("Unable to create circle image: " + ex);
     }
     return base.DrawChild(canvas, child, drawingTime);
 }
开发者ID:colbylwilliams,项目名称:BasicBeer-Forms,代码行数:34,代码来源:CircleImage.cs

示例6: OnDraw

		protected override void OnDraw(Canvas canvas)
		{
			base.OnDraw(canvas);

			DrawPaint.Color = CurrentLineColor;
			canvas.DrawBitmap(CanvasBitmap, 0, 0, CanvasPaint);
			canvas.DrawPath(DrawPath, DrawPaint);
		}
开发者ID:kimuraeiji214,项目名称:Keys,代码行数:8,代码来源:DrawView.cs

示例7: parse

		public void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint) {
			Path path = this.parse(pSVGProperties);

			bool fill = pSVGPaint.setFill(pSVGProperties);
			if (fill) {
				pCanvas.DrawPath(path, pSVGPaint.getPaint());
			}

			bool stroke = pSVGPaint.setStroke(pSVGProperties);
			if (stroke) {
				pCanvas.DrawPath(path, pSVGPaint.getPaint());
			}

			if(fill || stroke) {
				pSVGPaint.ensureComputedBoundsInclude(path);
			}
		}
开发者ID:jdluzen,项目名称:xamsvg,代码行数:17,代码来源:SVGPathParser.cs

示例8: ShowPath

 private void ShowPath(Canvas canvas, int x, int y, Path.FillType ft, Paint paint)
 {
     canvas.Save();
     canvas.Translate(x, y);
     canvas.ClipRect(0, 0, 120, 120);
     canvas.DrawColor(Color.White);
     mPath.SetFillType(ft);
     canvas.DrawPath(mPath, paint);
     canvas.Restore();
 }
开发者ID:Cheesebaron,项目名称:MonoDroid.PathFillTypes,代码行数:10,代码来源:PathFillSampleView.cs

示例9: OnDraw

		protected override void OnDraw (Canvas canvas)
		{
			base.OnDraw (canvas);

			float l = 0;
			float t = Height - PaddingBottom - DipToPixels (Context, 217);
			float r = Width - PaddingRight;
			float b = Height - DipToPixels (Context, 60);

			canvas.DrawRect (l, t, r, b, boxPaint);
			canvas.DrawPath (path, pathPaint);
		}
开发者ID:cyecp,项目名称:XamarinComponents,代码行数:12,代码来源:DrawView.cs

示例10: parse

		public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint) {
			var points = pSVGProperties.GetStringAttribute(SVGConstants.ATTRIBUTE_POINTS).ParseFloats ();
			if (points != null) {
				if (points.Length >= 2) {
					Path path = SVGPolylineParser.parse(points);

					bool fill = pSVGPaint.setFill(pSVGProperties);
					if (fill) {
						pCanvas.DrawPath(path, pSVGPaint.getPaint());
					}

					bool stroke = pSVGPaint.setStroke(pSVGProperties);
					if (stroke) {
						pCanvas.DrawPath(path, pSVGPaint.getPaint());
					}

					if(fill || stroke) {
						pSVGPaint.ensureComputedBoundsInclude(path);
					}
				}
			}
		}
开发者ID:jdluzen,项目名称:xamsvg,代码行数:22,代码来源:SVGPolylineParser.cs

示例11: DrawChild

        /// <summary>
        /// Redraws the child.
        /// </summary>
        protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
        {
            try
            {
                var radius = (float)((RoundedImage)Element).BorderRadius;
                var stroke = (float)((RoundedImage)Element).BorderThickness;
                var delta = (float)stroke / 2.0f;

                if (radius < 0)
                {
                    radius = Math.Min(Width, Height) / 2.0f;
                }

                radius -= delta;

                // Clip with rounded rect
                var path = new Path();
                path.AddRoundRect(new RectF(delta, delta, Width - stroke, Height - stroke),
                    radius, radius, Path.Direction.Ccw);
                canvas.Save();
                canvas.ClipPath(path);
                path.Dispose();

                var result = base.DrawChild(canvas, child, drawingTime);

                canvas.Restore();

                // Add stroke for smoother border
                path = new Path();
                path.AddRoundRect(new RectF(delta, delta, Width - stroke, Height - stroke),
                    radius, radius, Path.Direction.Ccw);
                var paint = new Paint();
                paint.AntiAlias = true;
                paint.StrokeWidth = stroke;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = ((RoundedImage)Element).BorderColor.ToAndroid();
                canvas.DrawPath(path, paint);
                paint.Dispose();

                // Clean up
                path.Dispose();

                return result;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }

            return base.DrawChild(canvas, child, drawingTime);
        }
开发者ID:TheUniforms,项目名称:Forms-Images,代码行数:54,代码来源:RoundedImageRenderer.cs

示例12: DrawChild

        protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
        {
            try {
                // Extract properties
                var source = (CircularImage)Element;
                var borderWidth = source.BorderWidth;
                var borderColor = source.BorderColor.ToAndroid();

                var radius = Math.Min(Width, Height) / 2;
                var strokeWidth = 10;
                radius -= strokeWidth / 2;

                //Create path to clip
                var path = new Path();
                path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
                canvas.Save();
                canvas.ClipPath(path);

                var result = base.DrawChild(canvas, child, drawingTime);

                canvas.Restore();

                // Create path for circle border
                path = new Path();
                path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);

                var paint = new Paint();
                paint.AntiAlias = true;
                paint.StrokeWidth = borderWidth;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = borderColor;

                canvas.DrawPath(path, paint);

                //Properly dispose
                paint.Dispose();
                path.Dispose();
                return result;
            } catch (Exception ex) {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }

            return base.DrawChild(canvas, child, drawingTime);
        }
开发者ID:Caeno,项目名称:Lib-XamarinForms-Toolkit,代码行数:44,代码来源:CircularImageRenderer.cs

示例13: DrawChild

    /// <summary>
    /// 
    /// </summary>
    /// <param name="canvas"></param>
    /// <param name="child"></param>
    /// <param name="drawingTime"></param>
    /// <returns></returns>
    protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
    {
      try
      {
        var radius = Math.Min(Width, Height) / 2;
        var strokeWidth = 10;
        radius -= strokeWidth / 2;


        Path path = new Path();
        path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
        canvas.Save();
        canvas.ClipPath(path);

        var result = base.DrawChild(canvas, child, drawingTime);

        canvas.Restore();

        path = new Path();
        path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);

        var paint = new Paint();
        paint.AntiAlias = true;
        paint.StrokeWidth = ((CircleImage)Element).BorderThickness;
        paint.SetStyle(Paint.Style.Stroke);
        paint.Color = ((CircleImage)Element).BorderColor.ToAndroid();

        canvas.DrawPath(path, paint);

        paint.Dispose();
        path.Dispose();
        return result;
      }
      catch (Exception ex)
      {
        System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
      }

      return base.DrawChild(canvas, child, drawingTime);
    }
开发者ID:bsimser,项目名称:Hanselman.Forms,代码行数:47,代码来源:ImageCircleRenderer.cs

示例14: OnDraw

        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            var path = new Path();
            path.MoveTo(_points[0].X, _points[0].Y);
            for (var i = 1; i < _points.Length; i++)
            {
                path.LineTo(_points[i].X, _points[i].Y);
            }

            var paint = new Paint
                            {
                                Color = Color.White
                            };

            // We can use Paint.Style.Stroke if we want to draw a "hollow" polygon,
            // But then we had better set the .StrokeWidth property on the paint.
            paint.SetStyle(Paint.Style.Fill);

            canvas.DrawPath(path, paint);
        }
开发者ID:eduardoguilarducci,项目名称:recipes,代码行数:22,代码来源:FilledPolygon.cs

示例15: DrawChild

		protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
		{
			try
			{
				var radius = Math.Min(Width, Height) / 2;
				var strokeWidth = 10;
				radius -= strokeWidth / 2;


				Path path = new Path();
				path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
				canvas.Save();
				canvas.ClipPath(path);

				var result = base.DrawChild(canvas, child, drawingTime);

				canvas.Restore();

				path = new Path();
				path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);

				var paint = new Paint();
				paint.AntiAlias = true;
				paint.StrokeWidth = 5;
				paint.SetStyle(Paint.Style.Stroke);
				paint.Color = global::Android.Graphics.Color.White;

				canvas.DrawPath(path, paint);

				paint.Dispose();
				path.Dispose();
				return result;
			}
			catch (Exception ex)
			{
			}

			return base.DrawChild(canvas, child, drawingTime);
		}
开发者ID:takigava,项目名称:PikabuFormsTest,代码行数:39,代码来源:ImageCircleRenderer.cs


注:本文中的Android.Graphics.Canvas.DrawPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。