本文整理汇总了C#中Android.Graphics.Path.AddRoundRect方法的典型用法代码示例。如果您正苦于以下问题:C# Path.AddRoundRect方法的具体用法?C# Path.AddRoundRect怎么用?C# Path.AddRoundRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Path
的用法示例。
在下文中一共展示了Path.AddRoundRect方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: Draw
/// <Docs>The Canvas to which the View is rendered.</Docs>
/// <summary>
/// Draw the specified canvas.
/// </summary>
/// <param name="canvas">Canvas.</param>
public override void Draw (Canvas canvas)
{
try
{
var element = Element as RoundCornerView;
var cornerRadius = (float)element.CornerRadius*Resources.DisplayMetrics.Density;
// Paint rounded rect itself
canvas.Save();
var paint = new Paint();
paint.AntiAlias = true;
var strokeWidth = (((float)element.BorderWidth)*Resources.DisplayMetrics.Density);
paint.StrokeWidth = strokeWidth;
if(element.BackgroundColor != Xamarin.Forms.Color.Transparent)
{
paint.SetStyle(Paint.Style.Fill);
paint.Color = element.BackgroundColor.ToAndroid();
canvas.DrawRoundRect(new RectF(0, 0, Width, Height), cornerRadius, cornerRadius, paint);
}
if(element.BorderColor != Xamarin.Forms.Color.Transparent)
{
paint.SetStyle(Paint.Style.Stroke);
paint.Color = element.BorderColor.ToAndroid();
canvas.DrawRoundRect(new RectF(0, 0, Width, Height), cornerRadius, cornerRadius, paint);
}
//Properly dispose
paint.Dispose();
canvas.Restore();
// Create clip path
var path = new Path();
path.AddRoundRect(new RectF(0.0f + (strokeWidth/2), 0.0f + (strokeWidth/2),
Width - (strokeWidth/2), Height - (strokeWidth/2)), cornerRadius, cornerRadius, Path.Direction.Cw);
canvas.Save();
canvas.ClipPath(path);
// Do base drawing
for(var i=0; i<ChildCount; i++)
GetChildAt(i).Draw(canvas);
canvas.Restore();
path.Dispose();
}
catch (Exception)
{
}
}
示例3: SetClipPath
public static void SetClipPath(this BorderRenderer br, Canvas canvas)
{
var clipPath = new Path();
//float padding = br;// radius / 2;
float radius = (float)br.Element.CornerRadius - br.Context.ToPixels((float)br.Element.Padding.ThickestSide());// - padding / 2; // + MaxStrokeThickness());
int w = (int)br.Width;
int h = (int)br.Height;
clipPath.AddRoundRect(new RectF(
br.ViewGroup.PaddingLeft,
br.ViewGroup.PaddingTop,
w - br.ViewGroup.PaddingRight,
h - br.ViewGroup.PaddingBottom),
radius,
radius,
Path.Direction.Cw);
canvas.ClipPath(clipPath);
}
示例4: DrawChild
protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
{
try
{
var path = new Path ();
path.AddRoundRect (new RectF (0, 0, Width, Height), 15f, 15f, Path.Direction.Ccw);
canvas.Save ();
canvas.ClipPath (path);
var result = base.DrawChild(canvas, child, drawingTime);
canvas.Restore();
path.Dispose();
return result;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Unable to create rounded rectangle image: " + ex);
}
return base.DrawChild(canvas, child, drawingTime);
}
示例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);
}
示例6: DrawOutline
void DrawOutline(Canvas canvas, int width, int height)
{
if (Button.BorderWidth <= 0)
return;
using (var paint = new Paint { AntiAlias = true })
using (var path = new Path())
{
float borderWidth = Forms.Context.ToPixels(Button.BorderWidth);
float inset = borderWidth / 2;
// adjust border radius so outer edge of stroke is same radius as border radius of background
float borderRadius = Forms.Context.ToPixels(Button.BorderRadius) - inset;
path.AddRoundRect(new RectF(inset, inset, width - inset, height - inset), borderRadius, borderRadius, Path.Direction.Cw);
paint.StrokeWidth = borderWidth;
paint.SetStyle(Paint.Style.Stroke);
paint.Color = Button.BorderColor.ToAndroid();
canvas.DrawPath(path, paint);
}
}
示例7: DrawBackground
void DrawBackground(Canvas canvas, int width, int height, bool pressed)
{
var paint = new Paint { AntiAlias = true };
var path = new Path();
float borderRadius = Forms.Context.ToPixels(Button.BorderRadius);
path.AddRoundRect(new RectF(0, 0, width, height), borderRadius, borderRadius, Path.Direction.Cw);
paint.Color = pressed ? Button.BackgroundColor.AddLuminosity(-0.1).ToAndroid() : Button.BackgroundColor.ToAndroid();
paint.SetStyle(Paint.Style.Fill);
canvas.DrawPath(path, paint);
}
示例8: OnLayout
protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
{
base.OnLayout (changed, left, top, right, bottom);
clipMask = new Path ();
var rect = new RectF (0, 0, Width, Height);
clipMask.AddRoundRect (rect, cornerRadius, cornerRadius, Path.Direction.Cw);
}