本文整理汇总了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);
}
示例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;
}
}
示例3: OnDraw
protected override void OnDraw (Canvas canvas)
{
drawCanvas = canvas;
canvas.DrawBitmap(canvasBitmap, 0, 0, canvasPaint);
canvas.DrawPath(drawPath, drawPaint);
}
示例4: OnDraw
protected override void OnDraw (Canvas canvas)
{
if (this.currentPath == null || this.currentPath.IsEmpty)
return;
canvas.DrawPath (this.currentPath, this.currentPaint);
}
示例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);
}
示例6: OnDraw
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
DrawPaint.Color = CurrentLineColor;
canvas.DrawBitmap(CanvasBitmap, 0, 0, CanvasPaint);
canvas.DrawPath(DrawPath, DrawPaint);
}
示例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);
}
}
示例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();
}
示例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);
}
示例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);
}
}
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}