本文整理汇总了C#中Android.Graphics.Canvas.DrawRect方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.DrawRect方法的具体用法?C# Canvas.DrawRect怎么用?C# Canvas.DrawRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.DrawRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBackground
public override ImageReference GetBackground (int row, int col)
{
var pt = new Point (row, col);
ImageReference imgRef = null;
if(mBackgrounds.ContainsKey(pt))
imgRef = mBackgrounds [pt];
if (imgRef == null) {
var bm = Bitmap.CreateBitmap (200, 200, Bitmap.Config.Argb8888);
var c = new Canvas (bm);
var p = new Paint ();
c.DrawRect (0, 0, 200, 200, p);
p.AntiAlias = true;
p.SetTypeface (Typeface.Default);
p.TextSize = 64;
p.Color = Color.LightGray;
c.DrawText (col + "-" + row, 20, 100, p);
imgRef = ImageReference.ForBitmap (bm);
mBackgrounds.Add (pt, imgRef);
}
return imgRef;
}
示例2: CreateBitmapData
void CreateBitmapData (string str, out byte[] bitmapData, out int width, out int height)
{
Paint paint = new Paint ();
paint.TextSize = 128;
paint.TextAlign = Paint.Align.Left;
paint.SetTypeface (Typeface.Default);
width = height = 256;
float textWidth = paint.MeasureText (str);
using (Bitmap bitmap = Bitmap.CreateBitmap (width, height, Bitmap.Config.Argb8888)) {
Canvas canvas = new Canvas (bitmap);
paint.Color = str != " " ? Color.White : Color.LightGray;
canvas.DrawRect (new Rect (0, 0, width, height), paint);
paint.Color = Color.Black;
canvas.DrawText (str, (256 - textWidth) / 2f, (256 - paint.Descent () - paint.Ascent ()) / 2f, paint);
bitmapData = new byte [width * height * 4];
Java.Nio.ByteBuffer buffer = Java.Nio.ByteBuffer.Allocate (bitmapData.Length);
bitmap.CopyPixelsToBuffer (buffer);
buffer.Rewind ();
buffer.Get (bitmapData, 0, bitmapData.Length);
}
}
示例3: 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());
}
}
示例4: OnDraw
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
canvas.DrawRect(0,0,Width,Height, new Paint
{
Color=Color.Black
});
canvas.DrawRect(1, 1, Width - 1, Height - 1, new Paint
{
Color = BackgroundColor
});
}
示例5: parse
public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint, RectF pRect) {
float x = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_X, 0f);
float y = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_Y, 0f);
float width = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_WIDTH, 0f);
float height = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_HEIGHT, 0f);
pRect.Set(x, y, x + width, y + height);
float? rX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_X);
float? rY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_Y);
bool rXSpecified = rX != null && rX >= 0;
bool rYSpecified = rY != null && rY >= 0;
bool rounded = rXSpecified || rYSpecified;
float rx;
float ry;
if(rXSpecified && rYSpecified) {
rx = Math.Min(rX.Value, width * 0.5f);
ry = Math.Min(rY.Value, height * 0.5f);
} else if(rXSpecified) {
ry = rx = Math.Min(rX.Value, width * 0.5f);
} else if(rYSpecified) {
rx = ry = Math.Min(rY.Value, height * 0.5f);
} else {
rx = 0;
ry = 0;
}
bool fill = pSVGPaint.setFill(pSVGProperties);
if (fill) {
if(rounded) {
pCanvas.DrawRoundRect(pRect, rx, ry, pSVGPaint.getPaint());
} else {
pCanvas.DrawRect(pRect, pSVGPaint.getPaint());
}
}
bool stroke = pSVGPaint.setStroke(pSVGProperties);
if (stroke) {
if(rounded) {
pCanvas.DrawRoundRect(pRect, rx, ry, pSVGPaint.getPaint());
} else {
pCanvas.DrawRect(pRect, pSVGPaint.getPaint());
}
}
if(fill || stroke) {
pSVGPaint.ensureComputedBoundsInclude(x, y, width, height);
}
}
示例6: OnDraw
protected override void OnDraw(Canvas canvas)
{
RectF rect = _colorRect;
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (BorderWidthPx > 0)
{
_borderPaint.Color = new Color((int) _borderColor);
canvas.DrawRect(_drawingRect, _borderPaint);
}
_colorPaint.Color = new Color((int) _color);
canvas.DrawRect(rect, _colorPaint);
}
示例7: 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;
}
}
示例8: OnDraw
protected override void OnDraw(Canvas canvas)
{
Paint p = new Paint();
Paint n = new Paint();
n.Color = (Color.Black);
n.TextAlign = (Paint.Align.Center);
p.Color = (Color.Blue);
p.Alpha = (50);
canvas.DrawRect(picker, p);
int[,] field = GameController.getInstance().getNumbers();
float widthStep = (float)MeasuredWidth/9;
float heightStep = (float)MeasuredHeight/9;
n.TextSize = (heightStep);
int[,] initial = GameController.getInstance().getInitialNumber();
for (int i = 0; i < 9; i++){
for (int q = 0; q < 9; q++){
if (initial[i,q] != 0){
canvas.DrawText(initial[i,q] + "", widthStep*q + (widthStep / 2),
heightStep*i + heightStep - (heightStep*0.1f), n);
}
}
}
n.Alpha = (150);
for (int i = 0; i < 9; i++){
for (int q = 0; q < 9; q++){
if (field[i,q] != 0){
canvas.DrawText(field[i,q] + "", widthStep*i + (widthStep / 2),
heightStep*q + heightStep - (heightStep*0.1f), n);
}
}
}
base.OnDraw(canvas);
}
示例9: DispatchDraw
protected override void DispatchDraw (Canvas canvas)
{
base.DispatchDraw (canvas);
if (FadeLength > 0) {
var isHoriz = Orientation == Orientation.Horizontal;
fadeRect.Right = canvas.Width;
fadeRect.Bottom = canvas.Height;
if (isHoriz) {
// On the right
fadeRect.Left = canvas.Width - FadeLength;
fadeRect.Top = 0;
} else {
// On the bottom
fadeRect.Left = 0;
fadeRect.Top = canvas.Height - FadeLength;
}
var gradient = new LinearGradient (
fadeRect.Left, fadeRect.Top,
isHoriz ? fadeRect.Right : fadeRect.Left, isHoriz ? fadeRect.Top : fadeRect.Bottom,
new Color (255, 255, 255, 255), new Color (255, 255, 255, 0),
Shader.TileMode.Clamp);
fadePaint.SetShader (gradient);
canvas.DrawRect (fadeRect, fadePaint);
}
}
示例10: Draw
public override void Draw(Canvas canvas)
{
LoadResources ();
var blackPaint = new Paint () { Color = black.Value };
var whitePaint = new Paint () { Color = white.Value };
XamGame.RenderBoard ((RectangleF rect, Square.ColourNames color) =>
{
var paint = color == Square.ColourNames.White ? whitePaint : blackPaint;
canvas.DrawRect (rect.X, rect.Y, rect.Right, rect.Bottom, paint);
}, (RectangleF rect, object image) =>
{
if (image != null)
canvas.DrawBitmap ((Bitmap) image, rect.Left, rect.Top, null);
});
// New Game button
whitePaint.Color = white.Value;
whitePaint.SetStyle (Paint.Style.Fill);
whitePaint.TextSize = 30;
whitePaint.AntiAlias = true;
Rect bounds = new Rect ();
whitePaint.GetTextBounds ("New Game", 0, 8, bounds);
canvas.DrawText ("New Game", (this.Width - bounds.Width ()) / 2, this.Bottom - (XamGame.BoardUpperLeftCorner.Y - bounds.Height ()) / 2, whitePaint);
whitePaint.Dispose ();
blackPaint.Dispose ();
base.Draw (canvas);
}
示例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;
}
示例12: HandleShapeDraw
protected virtual void HandleShapeDraw (Canvas canvas)
{
// We need to account for offsetting the coordinates based on the padding
var x = GetX () + Resize (this.ShapeView.Padding.Left);
var y = GetY () + Resize (this.ShapeView.Padding.Top);
switch (ShapeView.ShapeType) {
case ShapeType.Box:
HandleStandardDraw (canvas, p => {
var rect = new RectF (x, y, x + this.Width, y + this.Height);
if (ShapeView.CornerRadius > 0) {
var cr = Resize (ShapeView.CornerRadius);
canvas.DrawRoundRect (rect, cr, cr, p);
} else {
canvas.DrawRect (rect, p);
}
});
break;
case ShapeType.Circle:
HandleStandardDraw (canvas, p => canvas.DrawCircle (x + this.Width / 2, y + this.Height / 2, (this.Width - 10) / 2, p));
break;
case ShapeType.CircleIndicator:
HandleStandardDraw (canvas, p => canvas.DrawCircle (x + this.Width / 2, y + this.Height / 2, (this.Width - 10) / 2, p), drawFill: false);
HandleStandardDraw (canvas, p => canvas.DrawArc (new RectF (x, y, x + this.Width, y + this.Height), QuarterTurnCounterClockwise, 360 * (ShapeView.IndicatorPercentage / 100), false, p), ShapeView.StrokeWidth + 3, false);
break;
}
}
示例13: Draw
public override void Draw (Canvas canvas)
{
if (gradientColor == null) {
return;
}
canvas.DrawRect (Bounds, paint);
}
示例14: DrawRectangle
private static void DrawRectangle(Canvas canvas, RectF destination, Styles.Color outlineColor)
{
var paint = new Paint();
paint.SetStyle(Paint.Style.Stroke);
paint.Color = new AndroidColor(outlineColor.R, outlineColor.G, outlineColor.B, outlineColor.A);
paint.StrokeWidth = 4;
canvas.DrawRect(destination, paint);
}
示例15: OnDraw
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
float middle = canvas.Width * (float)_position;
canvas.DrawPaint(_negativePaint);
canvas.DrawRect(0, 0, middle, canvas.Height, _positivePaint);
}