本文整理汇总了C#中Android.Graphics.Canvas.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.Save方法的具体用法?C# Canvas.Save怎么用?C# Canvas.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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)
{
}
}
示例2: OnDraw
protected override void OnDraw(Canvas canvas) {
base.OnDraw (canvas);
if (mBlurredView != null) {
if (prepare()) {
// If the background of the blurred view is a color drawable, we use it to clear
// the blurring canvas, which ensures that edges of the child views are blurred
// as well; otherwise we clear the blurring canvas with a transparent color.
if (mBlurredView.Background != null && mBlurredView.Background is ColorDrawable){
mBitmapToBlur.EraseColor(((ColorDrawable) mBlurredView.Background).Color);
}else {
mBitmapToBlur.EraseColor(Color.Transparent);
}
mBlurredView.Draw(mBlurringCanvas);
blur();
canvas.Save();
canvas.Translate(mBlurredView.GetX() - GetX(), mBlurredView.GetY() - GetY());
canvas.Scale(mDownsampleFactor, mDownsampleFactor);
canvas.DrawBitmap(mBlurredBitmap, 0, 0, null);
canvas.Restore();
}
canvas.DrawColor(mOverlayColor);
}
}
示例3: 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);
}
示例4: drawPorcentajeOnCanvas
private void drawPorcentajeOnCanvas(Canvas canvas)
{
base.OnDraw (canvas);
canvas.Save ();
canvas.DrawColor(Android.Graphics.Color.White);
//Obtenemos el centro de nuesto canvas
float x = this.MeasuredWidth / 2;
float y = this.MeasuredHeight / 2;
//Obtenemos el radio R1
//Obtenemos el radio R2
float R1 = 0;
float R2 = 0;
//if (canvas.Width < canvas.Height) {
if (this.MeasuredWidth < this.MeasuredHeight) {
R1 = x;//Obtenemos el radio R1
R2 = x-(x*por_rango/100);
} else {
R1 = y ;//Obtenemos el radio R1
R2 = y-(y *por_rango/100);//Obtenemos el radio R2 que dejamos un 20% de margen
}
//Dibujamos el fondo de nuestro grafico que va ir creciendo de acuerdo al porcentaje descargado
RectF rectF2 = new RectF(x-R1, y-R1,x+R1, y+R1);
mPaintFondo.Color= Android.Graphics.Color.Rgb(19,184,213);
int grados = 0;
grados = 360 * porcentaje / 100;
canvas.DrawArc(rectF2, 270, grados, true, mPaintFondo);
//Fondo superior de nuestro texto
mPaintSuperior.Color= Android.Graphics.Color.Rgb(50,58,69);
canvas.DrawCircle(x,y , R2, mPaintSuperior);
//Texto que nos indica el procentaje descargado
mPaintTexto.SetTypeface (mFace);
mPaintTexto.Color = Color.White;
//Obtenemos el 30 % de radio de nuestro circulo de fondo, el cual sera el tamaño de letra utilzar;
float MYTEXTSIZE = R2 *30/100;
// Get the screen's density scale
float scale = Application.Context.Resources.DisplayMetrics.Density;
//Convert the dps to pixels, based on density scale
int textSizePx = (int) (MYTEXTSIZE * scale + 0.5f);
mPaintTexto.TextSize = textSizePx;
//Obtenemos la posicion para centrar adecuadamente nuesto texto
int xPos = (this.MeasuredWidth / 2);
int yPos = (int) ((this.MeasuredHeight / 2) - ((mPaintTexto.Descent() + mPaintTexto.Ascent()) / 2)) ;
string Texto_Porcentaje =porcentaje.ToString();
canvas.DrawText (Texto_Porcentaje+" %", xPos,yPos, mPaintTexto);
canvas.Restore();
}
示例5: DrawStopwatch
public void DrawStopwatch(Canvas canvas)
{
canvas.Save();
canvas.Translate(Width / 2F, Height / 2F);
var tickMarks = new Path();
tickMarks.AddCircle(0, 0, 90, Path.Direction.Cw);
var scale = Math.Min(Width, Height) / 2F / 120;
canvas.Scale(scale, scale);
var paint = new Paint
{
StrokeCap = Paint.Cap.Square,
Color = new Color(240, 240, 240)
};
paint.SetStyle(Paint.Style.Stroke);
paint.StrokeWidth = 3;
paint.SetPathEffect(MinuteDashEffect);
canvas.DrawPath(tickMarks, paint);
paint.Color = new Color(240, 240, 240);
paint.StrokeWidth = 4;
paint.SetPathEffect(FifthMinuteDashEffect);
canvas.DrawPath(tickMarks, paint);
}
示例6: DrawChild
/// <summary>
///
/// </summary>
/// <param name="canvas"></param>
/// <param name="child"></param>
/// <param name="drawingTime"></param>
/// <returns></returns>
protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime)
{
try
{
var radius = Math.Min(Width, Height) / 2;
var strokeWidth = ((CircleImage)Element).BorderThickness;
radius -= strokeWidth / 2;
var path = new Path();
path.AddCircle(Width / 2, Height / 2, 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(Width / 2, Height / 2, radius, Path.Direction.Ccw);
var thickness = ((CircleImage)Element).BorderThickness;
if(thickness > 0.0f)
{
paint = new Paint();
paint.AntiAlias = true;
paint.StrokeWidth = thickness;
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);
}
示例7: Draw
public void Draw(Canvas canvas)
{
canvas.Save();
canvas.Translate((float)Position.X, (float)Position.Y);
canvas.Rotate((float)Acceleration.Direction + ROTATION_OFFSET);
mDrawable.Draw(canvas);
canvas.Restore();
}
示例8: 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);
}
示例9: OnDraw
protected override void OnDraw (Canvas canvas)
{
base.OnDraw (canvas);
canvas.Save ();
canvas.Translate (_posX, _posY);
canvas.Scale (_scaleFactor, _scaleFactor);
_icon.Draw (canvas);
canvas.Restore ();
}
示例10: DispatchDraw
// Rotate the canvas before drawing
protected override void DispatchDraw(Canvas canvas)
{
canvas.Save (SaveFlags.Matrix);
canvas.Rotate (-heading, Width * 0.5f, Height * 0.5f);
base.DispatchDraw (canvas);
canvas.Restore ();
}
示例11: 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();
}
示例12: OnDraw
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
DrawHexagon(canvas);
canvas.Save();
canvas.Scale(.4f, .5f, Width / 2, Height / 2);
DrawCross(canvas);
canvas.Restore();
}
示例13: OnDraw
protected override void OnDraw(Canvas canvas)
{
for (int i = 0; i < balls.Count; ++i)
{
ShapeHolder shapeHolder = balls[i];
canvas.Save();
canvas.Translate(shapeHolder.X, shapeHolder.Y);
shapeHolder.Shape.Draw(canvas);
canvas.Restore();
}
}
示例14: OnDraw
protected override void OnDraw(Canvas canvas)
{
canvas.Save();
if (RotationPivotPoint != null) {
canvas.Rotate(RotationDegress, RotationPivotPoint.X, RotationPivotPoint.Y);
} else {
canvas.Rotate(RotationDegress);
}
base.OnDraw(canvas);
}
示例15: Draw
public override void Draw(Canvas canvas, ICharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint)
{
PrepView();
canvas.Save();
//Centering the token looks like a better strategy that aligning the bottom
int padding = (bottom - top - View.Bottom) / 2;
canvas.Translate(x, bottom - View.Bottom - padding);
View.Draw(canvas);
canvas.Restore();
}