當前位置: 首頁>>代碼示例>>C#>>正文


C# Android.DrawPath方法代碼示例

本文整理匯總了C#中Android.DrawPath方法的典型用法代碼示例。如果您正苦於以下問題:C# Android.DrawPath方法的具體用法?C# Android.DrawPath怎麽用?C# Android.DrawPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Android的用法示例。


在下文中一共展示了Android.DrawPath方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Draw

        public override void Draw(Android.Graphics.Canvas canvas)
        {
            base.Draw(canvas);

            var rect = new RectF(0,0,300,300);
            switch (TheShape)
            {
                case Shape.Circle:
                    canvas.DrawOval(rect, new Paint() { Color = Color.Aqua });
                    break;
                case Shape.Square:
                    canvas.DrawRect(rect, new Paint() { Color = Color.Red });
                    break;
                case Shape.Triangle:
                    var path = new Path();
                    path.MoveTo(rect.CenterX(), 0);
                    path.LineTo(0, rect.Height());
                    path.LineTo(rect.Width(), rect.Height());
                    path.Close();

                    var paint = new Paint() {Color = Color.Magenta};
                    paint.SetStyle(Paint.Style.Fill);
                    canvas.DrawPath(path, paint);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
開發者ID:KiranKumarAlugonda,項目名稱:NPlus1DaysOfMvvmCross,代碼行數:29,代碼來源:CustomDrawShapeView.cs

示例2: OnDraw

        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            var rect = new RectF(0, 0, 300, 300);
            switch (Shape)
            {
                case Shape.Circle:
                    canvas.DrawOval(rect, new Paint() { Color = Color.CornflowerBlue });
                    break;
                case Shape.Square:
                    canvas.DrawRect(rect, new Paint() { Color = Color.Crimson });
                    break;
                case Shape.Triangle:

                    var path = new Path();
                    path.MoveTo(rect.CenterX(), rect.Top);
                    path.LineTo(rect.Left, rect.Bottom);
                    path.LineTo(rect.Right, rect.Bottom);
                    path.Close();
                    var paint = new Paint() {Color = Color.Crimson};
                    paint.Color = Color.Gold;
                    paint.SetStyle(Paint.Style.Fill);
                    canvas.DrawPath(path, paint);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
開發者ID:Coolerhino,項目名稱:MvvmCross-Tutorials,代碼行數:27,代碼來源:ShapeView.cs

示例3: Draw

		/// <Docs>The Canvas to which the View is rendered.</Docs>
		/// <summary>
		/// BoxViewのカスタマイズはDrawで行う
		/// </summary>
		/// <param name="canvas">Canvas.</param>
		public override void Draw(Android.Graphics.Canvas canvas)
		{
			// 2重に描畫してしまうので、baseは描畫しない
			//base.Draw(canvas);

			// ElementをキャストしてFormsで定義したCustomBoxViewを取得
			var formsBox = (CustomBoxView)Element;

			// Androidの描畫はPaintを使用
			using (var paint = new Paint()) 
			{
				// 塗りつぶし色の設定
				paint.Color = formsBox.FillColor.ToAndroid();

				// 吹き出し部分の設定
				// パスの生成
				var path = new Path();

				// スタート地點の設定
				path.MoveTo(0, 0);

				// 経由地點の設定
				path.LineTo(100, 10);
				path.LineTo(100, 100);

				// パスを繋げる
				path.Close();

				// 描畫
				canvas.DrawPath(path, paint);


				// 角の丸い四角の設定
				// 角丸の直徑を決める
				// widthとheightを比較して小さい方を基準にする
				var minSize = Math.Min(Width, Height);

				// 指定するのは直徑なので、指定半徑を2倍する
				var diameter = formsBox.Radius * 2;
				// 角丸の直徑はminSize以下でなければならない
				if (diameter > minSize)
					diameter = minSize;

				// 描畫領域の設定
				var rect = new RectF(0, 0, (float)Width, (float)Height);

				//四角形描畫
				canvas.DrawRoundRect(rect, diameter, diameter, paint);
			}
		}
開發者ID:mattsuDev,項目名稱:Xamarin.Forms.CustomBox,代碼行數:55,代碼來源:CustomBoxViewRenderer.cs

示例4: DrawChild

 protected override bool DrawChild(Android.Graphics.Canvas canvas, Android.Views.View child, long drawingTime)
 {
     try
     {
         var element = (RoundedImage)Element;
         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;
         //TODO look for a correct way to assign the BorderWidth depending of the screen dpi
         paint.StrokeWidth = (float)element.BorderWidth;
         paint.SetStyle(Paint.Style.Stroke);
         paint.Color = element.BorderColor.ToAndroid();
         canvas.DrawPath(path, paint);
         //Properly dispose
         paint.Dispose();
         path.Dispose();
         return result;
     }
     catch (Exception ex)
     {
         //Why this happend
         Console.WriteLine(ex.Message);
     }
     return base.DrawChild(canvas, child, drawingTime);
 }
開發者ID:codercampos,項目名稱:CrossFeaturesXamarin,代碼行數:37,代碼來源:RoundedImageRenderer.cs

示例5: OnDraw

        protected override void OnDraw(Shape shape, Android.Graphics.Canvas canvas, Paint paint)
        {
            var height = canvas.ClipBounds.Bottom;
            var width = canvas.ClipBounds.Right;
            if (noChild)
            {
                var borderHeight = (int)(this.borderThickness.Top + this.borderThickness.Bottom);
                var borderWidth = (int)(this.borderThickness.Left + this.borderThickness.Right);
                height = borderHeight > 0 ? borderHeight : canvas.ClipBounds.Bottom;
                width = borderWidth > 0 ? borderWidth : canvas.ClipBounds.Right;
            }
            shape.Resize(width, height);
            shape.Draw(canvas, strokepaint);

            var pathInner = new Path();
            var rect = new RectF(
                (float)(borderThickness.Left),
                (float)(borderThickness.Top),
                (float)(canvas.ClipBounds.Right - borderThickness.Right),
                (float)(canvas.ClipBounds.Bottom - borderThickness.Bottom));
            pathInner.AddRoundRect(rect, cornerRadiusArray, Path.Direction.Cw);
            if (!noChild)
            {
                var clearPaint = new Paint();
                clearPaint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.Clear));
                canvas.DrawPath(pathInner, clearPaint);
            }
            canvas.DrawPath(pathInner, fillpaint);
        }
開發者ID:evnik,項目名稱:UIFramework,代碼行數:29,代碼來源:Border.Droid.cs

示例6: OnDraw

		protected override void OnDraw (Android.Graphics.Canvas canvas)
		{
			canvas.DrawBitmap (canvasBitmap, 0, 0, canvasPaint);
			canvas.DrawPath (drawPath, drawPaint);
		}
開發者ID:Ajhenk0955,項目名稱:BlueNet,代碼行數:5,代碼來源:DrawTest.cs


注:本文中的Android.DrawPath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。