本文整理汇总了C#中Android.Graphics.Canvas类的典型用法代码示例。如果您正苦于以下问题:C# Canvas类的具体用法?C# Canvas怎么用?C# Canvas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Canvas类属于Android.Graphics命名空间,在下文中一共展示了Canvas类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetCroppedBitmap
static Bitmap GetCroppedBitmap (Bitmap bmp, int radius)
{
Bitmap sbmp;
if (bmp.Width != radius || bmp.Height != radius)
sbmp = Bitmap.CreateScaledBitmap (bmp, radius, radius, false);
else
sbmp = bmp;
var output = Bitmap.CreateBitmap (sbmp.Width,
sbmp.Height, Bitmap.Config.Argb8888);
var canvas = new Canvas (output);
var paint = new Paint ();
var rect = new Rect (0, 0, sbmp.Width, sbmp.Height);
paint.AntiAlias = true;
paint.FilterBitmap = true;
paint.Dither = true;
canvas.DrawARGB (0, 0, 0, 0);
paint.Color = Color.ParseColor ("#BAB399");
canvas.DrawCircle (sbmp.Width / 2 + 0.7f, sbmp.Height / 2 + 0.7f,
sbmp.Width / 2 + 0.1f, paint);
paint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.SrcIn));
canvas.DrawBitmap (sbmp, rect, rect, paint);
return output;
}
开发者ID:vgvassilev,项目名称:couchbase-connect-14,代码行数:26,代码来源:RoundedImageView.cs
示例2: draw
public void draw(Canvas canvas) {
pathA.getPointOnLine(parameter, coordsA);
pathB.getPointOnLine(parameter, coordsB);
if (rounded) insetPointsForRoundCaps();
canvas.DrawLine(coordsA[0], coordsA[1], coordsB[0], coordsB[1], linePaint);
}
开发者ID:jeedey93,项目名称:xamarin-android-samples,代码行数:7,代码来源:DrawerArrowDrawable.cs
示例3: Draw
public override void Draw(Canvas canvas)
{
foreach (Chaser chaser in _chasers)
{
chaser.Draw(canvas);
}
}
开发者ID:Verdungo,项目名称:testRep,代码行数:7,代码来源:DrawingView.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: Draw
public static void Draw(Canvas canvas, IViewport viewport, IStyle style, IFeature feature)
{
try
{
if (!feature.RenderedGeometry.ContainsKey(style)) feature.RenderedGeometry[style] = ToAndroidBitmap(feature.Geometry);
var bitmap = (AndroidGraphics.Bitmap)feature.RenderedGeometry[style];
var dest = WorldToScreen(viewport, feature.Geometry.GetBoundingBox());
dest = new BoundingBox(
dest.MinX,
dest.MinY,
dest.MaxX,
dest.MaxY);
var destination = RoundToPixel(dest);
using (var paint = new Paint())
{
canvas.DrawBitmap(bitmap, new Rect(0, 0, bitmap.Width, bitmap.Height), destination, paint);
}
DrawOutline(canvas, style, destination);
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
}
}
开发者ID:jdeksup,项目名称:Mapsui.Net4,代码行数:28,代码来源:RasterRenderer.cs
示例6: 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
示例7: 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();
}
开发者ID:DiLRandI,项目名称:Xamarin.android,代码行数:60,代码来源:ProgressCircleView.cs
示例8: Draw
public new void Draw(Canvas canvas, Paint paint)
{
int viewWidth = mProgressBar.Width;
int viewHeight = mProgressBar.Height;
canvas.DrawCircle(viewWidth / 2, viewHeight / 2, (mCircleDiameter / 2 + mShadowRadius), mShadowPaint);
canvas.DrawCircle(viewWidth / 2, viewHeight / 2, (mCircleDiameter / 2), paint);
}
开发者ID:devxiaruwei,项目名称:MaterialProgressbar,代码行数:7,代码来源:OvalShadow.cs
示例9: Draw
public override void Draw(Canvas canvas)
{
foreach (CirclePaint item in _touches)
{
item.Draw(canvas);
}
}
开发者ID:Verdungo,项目名称:testRep,代码行数:7,代码来源:DrawingView.cs
示例10: 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);
}
开发者ID:adolfo7x,项目名称:Play.Stopwatch,代码行数:27,代码来源:StopwatchView.cs
示例11: GetBackgroundForPage
public override Android.Graphics.Drawables.Drawable GetBackgroundForPage (int row, int column)
{
Point pt = new Point (column, row);
Drawable drawable;
if (!mBackgrounds.ContainsKey(pt))
{
// the key wasn't found in Dictionary
var bm = Bitmap.CreateBitmap(200, 200, Bitmap.Config.Argb8888);
var c = new Canvas(bm);
var p = new Paint();
// Clear previous image.
c.DrawRect(0, 0, 200, 200, p);
p.AntiAlias = true;
p.SetTypeface(Typeface.Default);
p.TextSize = 64;
p.Color = Color.LightGray;
p.TextAlign = Paint.Align.Center;
c.DrawText(column + "-" + row, 100, 100, p);
drawable = new BitmapDrawable(owner.Resources, bm);
mBackgrounds.Add(pt, drawable);
}
else
{
// the key was found
drawable = mBackgrounds[pt];
}
return drawable;
}
开发者ID:xamarin,项目名称:monodroid-samples,代码行数:28,代码来源:GridExampleActivity.cs
示例12: DispatchDraw
protected override void DispatchDraw (Canvas canvas)
{
base.DispatchDraw (canvas);
if (!firstTime)
return;
for(int i = 0; i< tabs.TabCount; i++)
{
var tab = tabs.GetTabAt (i);
var page = tabbedPage.Children [tab.Position];
if (page is TabPage) {
var tPage = (TabPage)page;
SetTab (tab, (tabs.SelectedTabPosition == tab.Position) ? tPage.SelectedIcon.File : tPage.Icon.File);
} else
{
SetTab (tab, page.Icon.File);
}
if (!tabbedPage.ShowTitles)
{
tab.SetText (string.Empty);
}
}
firstTime = false;
}
开发者ID:patrickpetropoulos,项目名称:Xamarin.Samples,代码行数:33,代码来源:CustomTabbedPageRenderer.cs
示例13: transformCanvas
public void transformCanvas(Canvas canvas, float percentOpen)
{
mtrans.transformCanvas(canvas, percentOpen);
float f = minterp.GetInterpolation(percentOpen);
canvas.Scale((mopenedX - mclosedX) * f + mclosedX,
(mopenedY - mclosedY) * f + mclosedY, mpx, mpy);
}
开发者ID:skywolf888,项目名称:SlidingMenu.Net,代码行数:7,代码来源:CanvasTransformerBuilder.cs
示例14: OnDraw
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
_buttonBackgroundPaint.Color = _backgroundColor;
float diameter = _radius * 2;
float uWidth = PaddingLeft == 0 && PaddingRight == 0 ? diameter : Width - PaddingLeft - PaddingRight;
float uHeight = PaddingBottom == 0 && PaddingTop == 0 ? diameter : Height - PaddingTop - PaddingBottom;
float cx = uWidth / 2;
float cy = uHeight / 2;
float radius = Math.Min(uWidth - DipToPixels(2), uHeight - DipToPixels(2)) / 2;
if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb)
{
SetLayerType(LayerType.Software, null);
}
_shadowPaint.SetShadowLayer(10, 0, 0, _shadowColor);
canvas.DrawCircle(cx, cy, radius - 4, _shadowPaint);
canvas.DrawCircle(cx, cy, radius, _buttonBackgroundPaint);
int sidePadding = (int)(_radius * 0.25);
int ulPadding = (int)(_radius * (0.25 + _contentScale));
_drawableContent?.SetBounds(sidePadding, sidePadding, ulPadding, ulPadding);
_drawableContent?.Draw(canvas);
}
开发者ID:heith,项目名称:Xamarin.Android.FloatingActionButton,代码行数:25,代码来源:FloatingActionButton.cs
示例15: Draw
public override void Draw (Canvas canvas)
{
var bounds = Bounds;
if (alpha != 255) {
paint.Alpha = 255;
if (SecondBitmap != null) {
if (shader1 == null)
shader1 = new BitmapShader (FirstBitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
shader1.SetLocalMatrix (matrix);
paint.SetShader (shader1);
canvas.DrawRect (bounds, paint);
} else
canvas.DrawColor (defaultColor.ToAndroidColor());
}
if (alpha != 0) {
paint.Alpha = alpha;
if (FirstBitmap != null) {
if (shader2 == null)
shader2 = new BitmapShader (SecondBitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
shader2.SetLocalMatrix (matrix);
paint.SetShader (shader2);
canvas.DrawRect (bounds, paint);
} else
canvas.DrawColor (defaultColor.ToAndroidColor());
}
}
开发者ID:rmarinho,项目名称:xamarin-store-app,代码行数:27,代码来源:KenBurnsDrawable.cs
示例16: OnDraw
//protected override void OnElementChanged(VisualElement oldModel, VisualElement newModel)
//protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
protected override void OnDraw(Canvas canvas)
{
_activity = this.Context as Activity;
ActionBar actionBar = _activity.ActionBar;
if (actionBar.TabCount > 0)
{
ActionBar.Tab tabPrompting = actionBar.GetTabAt(0);
ActionBar.Tab tabActivities = actionBar.GetTabAt(1);
ActionBar.Tab tabReminders = actionBar.GetTabAt(2);
ActionBar.Tab tabMapping = actionBar.GetTabAt(3);
ActionBar.Tab tabSettings = actionBar.GetTabAt(4);
//Set the tab icons
tabPrompting.SetIcon(Resource.Drawable.ic_description_white_24dp);
tabActivities.SetIcon(Resource.Drawable.ic_local_activity_white_24dp);
tabReminders.SetIcon(Resource.Drawable.ic_schedule_white_24dp);
tabMapping.SetIcon(Resource.Drawable.ic_map_white_24dp);
tabSettings.SetIcon(Resource.Drawable.ic_settings_white_24dp);
//Remove the page's title from the tab
tabPrompting.SetText("");
tabActivities.SetText("");
tabReminders.SetText("");
tabMapping.SetText("");
tabSettings.SetText("");
base.OnDraw(canvas);
}
}
开发者ID:FishSaidNo,项目名称:IAB330-CaAPA,代码行数:32,代码来源:CustomTabRenderer.cs
示例17: 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
示例18: OnDraw
protected override void OnDraw(Canvas canvas)
{
base.OnDraw (canvas);
var r = new Rect ();
this.GetLocalVisibleRect (r);
var half = r.Width() / 2;
var height = r.Height();
var percentage = (this.Limit - Math.Abs(this.CurrentValue)) / this.Limit;
var paint = new Paint()
{
Color = this.CurrentValue < 0 ? this.negativeColor : this.positiveColor,
StrokeWidth = 5
};
paint.SetStyle(Paint.Style.Fill);
if (this.CurrentValue < 0)
{
var start = (float)percentage * half;
var size = half - start;
canvas.DrawRect (new Rect ((int)start, 0, (int)(start + size), height), paint);
}
else
{
canvas.DrawRect (new Rect((int)half, 0, (int)(half + percentage * half), height), paint);
}
}
开发者ID:GGHG72,项目名称:Xamarin-Forms-Labs,代码行数:32,代码来源:SensorBarDroidView.cs
示例19: ToBlurred
public static Bitmap ToBlurred(Bitmap source, Context context, float radius)
{
if ((int)Android.OS.Build.VERSION.SdkInt >= 17)
{
Bitmap bitmap = Bitmap.CreateBitmap(source.Width, source.Height, Bitmap.Config.Argb8888);
using (Canvas canvas = new Canvas(bitmap))
{
canvas.DrawBitmap(source, 0, 0, null);
using (Android.Renderscripts.RenderScript rs = Android.Renderscripts.RenderScript.Create(context))
{
using (Android.Renderscripts.Allocation overlayAlloc = Android.Renderscripts.Allocation.CreateFromBitmap(rs, bitmap))
{
using (Android.Renderscripts.ScriptIntrinsicBlur blur = Android.Renderscripts.ScriptIntrinsicBlur.Create(rs, overlayAlloc.Element))
{
blur.SetInput(overlayAlloc);
blur.SetRadius(radius);
blur.ForEach(overlayAlloc);
overlayAlloc.CopyTo(bitmap);
rs.Destroy();
return bitmap;
}
}
}
}
}
return ToLegacyBlurred(source, context, (int)radius);
}
开发者ID:tmkhanh,项目名称:FFImageLoading,代码行数:30,代码来源:BlurredTransformation.cs
示例20: Transform
public Bitmap Transform(Bitmap source)
{
int size = Math.Min(source.Width, source.Height);
int width = (source.Width - size) / 2;
int height = (source.Height - size) / 2;
var bitmap = Bitmap.CreateBitmap(size, size, Bitmap.Config.Argb4444);
var canvas = new Canvas(bitmap);
var paint = new Paint();
var shader =
new BitmapShader(source, BitmapShader.TileMode.Clamp, BitmapShader.TileMode.Clamp);
if (width != 0 || height != 0)
{
// source isn't square, move viewport to center
var matrix = new Matrix();
matrix.SetTranslate(-width, -height);
shader.SetLocalMatrix(matrix);
}
paint.SetShader(shader);
paint.AntiAlias = true;
float r = size / 2f;
canvas.DrawCircle(r, r, r, paint);
source.Recycle();
return bitmap;
}
开发者ID:nepula-h-okuyama,项目名称:DroidKaigi2016Xamarin,代码行数:30,代码来源:CropCircleTransformation.cs
注:本文中的Android.Graphics.Canvas类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论