本文整理汇总了C#中Paint.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Paint.Dispose方法的具体用法?C# Paint.Dispose怎么用?C# Paint.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Paint
的用法示例。
在下文中一共展示了Paint.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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);
}
示例4: 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);
}
示例5: 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)
{
}
}
示例6: Draw
public override void Draw(Canvas canvas)
{
Rect rectangle = new Rect();
GetDrawingRect(rectangle);
Paint paint = new Paint();
paint.AntiAlias = true;
paint.Color = Color.Gray;
paint.SetStyle(Paint.Style.Stroke);
canvas.DrawLine(rectangle.Left, rectangle.Bottom - 2, rectangle.Right, rectangle.Bottom, paint);
paint.Dispose();
base.Draw(canvas);
}
示例7: 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(Android.Graphics.Canvas canvas)
{
base.Draw(canvas);
var paintForAngle = new Paint { Color = (Android.Graphics.Color.White), TextSize = 37f };
paintForAngle.SetStyle(Paint.Style.Stroke);
paintForAngle.SetTypeface(Typeface.CreateFromAsset(Forms.Context.Assets, "Fonts/fontawesome.ttf"));
canvas.DrawText('\uf078'.ToString(), (float)(canvas.ClipBounds.CenterX() * 1.65), (float)(canvas.ClipBounds.CenterY() * 1.15), paintForAngle);
#region Disposing
paintForAngle.Dispose();
canvas.Dispose();
#endregion
}
示例8: 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);
}
示例9: 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);
}
示例10: 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);
}
示例11: DrawChild
protected override bool DrawChild(Android.Graphics.Canvas canvas, Android.Views.View child, long drawingTime)
{
try
{
var element = (RoundedImage)Element;
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;
//TODO look for a correct way to assign the BorderWidth depending of the screen dpi
paint.StrokeWidth = (float)element.BorderWidth;
paint.SetStyle(Paint.Style.Stroke);
paint.Color = element.BorderColor.ToAndroid();
canvas.DrawPath(path, paint);
//Properly dispose
paint.Dispose();
path.Dispose();
return result;
}
catch (Exception ex)
{
//Why this happend
Console.WriteLine(ex.Message);
}
return base.DrawChild(canvas, child, drawingTime);
}
示例12: OnDraw
//--------------------------------------------------------------
// EVENT METHODS
//--------------------------------------------------------------
// Draw every proposed piece in the accorded space
// each piece have the space for 5 blocks to draw itself on the width
// On the Height, each piece have 4 blocks to draw itself and there is one pixel to separate each one of them (because there is less space on the height)
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
// If it is the first draw, calculate the size of the block according to the size of the canvas
if(_blockSize == 0)
{
// Calculate the size of the block, Space for each piece set to 5 blocks (except for the last one)
_blockSize = Math.Min((Width - (_nbPieceByLine - 1) * StrokeWidthBorder)/(_nbPieceByLine*5),
(Height - (Constants.NbLinePropPiece - 1) * StrokeWidthBorder)/(Constants.NbLinePropPiece*5));
// Create the blocks images with the right size
foreach(TetrisColor color in Enum.GetValues(typeof(TetrisColor)))
{
Bitmap image = BlockView.CreateImage(_blockSize, color);
if(image != null)
{
_blockImages.Add(color, image);
}
}
_offset = new Point((Width - _nbPieceByLine*5*_blockSize - (_nbPieceByLine - 1) * StrokeWidthBorder) / 2,
(Height - Constants.NbLinePropPiece*5*_blockSize - (Constants.NbLinePropPiece - 1) * StrokeWidthBorder) / 2);
}
// Draw the pieces and highlight the selected one
for(int i = 0; i < Constants.NbProposedPiece; i++)
{
if(_proposedPieces[i] != null)
{
// Show the selected piece
if(i == _selectedPiece)
{
int left = ((i % _nbPieceByLine) == 0) ? 0 : _offset.X;
int right = (((i + 1) % _nbPieceByLine) == 0) ? Width : _offset.X;
int top = ((i / _nbPieceByLine) == 0) ? 0 : _offset.Y;
int bottom = (i >= (_nbPieceByLine * (Constants.NbLinePropPiece - 1))) ? Height : _offset.Y;
RectF rect = new RectF((i % _nbPieceByLine) * _blockSize * 5 + (i % _nbPieceByLine) * StrokeWidthBorder + left,
(_blockSize * 5) * (i / _nbPieceByLine) + (i / _nbPieceByLine) * StrokeWidthBorder + top,
((i % _nbPieceByLine) + 1) * _blockSize * 5 + (i % _nbPieceByLine) * StrokeWidthBorder + right,
(_blockSize * 5) * (1 + i / _nbPieceByLine) + (i / _nbPieceByLine) * StrokeWidthBorder + bottom);
Paint paint = new Paint {AntiAlias = true, Color = Utils.getAndroidReallyLightColor(TetrisColor.Red)};
//canvas.DrawRoundRect(rect, Constants.RadiusHighlight, Constants.RadiusHighlight, paint);
canvas.DrawRect(rect, paint);
paint.Dispose();
}
float xSize = 0;
float ySize = 0;
_proposedPieces[i].GetDrawnSize(_blockSize, ref xSize, ref ySize);
// Draw each piece
_proposedPieces[i].Draw(canvas, _blockSize, _blockImages,
(i % _nbPieceByLine) * _blockSize * 5 + (_blockSize * 5 - xSize) / 2 + _offset.X + (i % _nbPieceByLine) * StrokeWidthBorder,
Height - ((i / _nbPieceByLine + 1) * _blockSize * 5 - (_blockSize * 5 - ySize) / 2 + _offset.Y + (i / _nbPieceByLine) * StrokeWidthBorder),
Height);
}
}
// Grid
for(int i = 1; i < _nbPieceByLine; i++)
{
// Vertical
int x = _offset.X + i*5*_blockSize + (i - 1) * StrokeWidthBorder;
canvas.DrawRect(x, 0, x + StrokeWidthBorder, Height, GridPaint);
}
for(int i = 1; i < Constants.NbLinePropPiece; i++)
{
// Horizontal
int y = _offset.Y + i*5*_blockSize + (i - 1) * StrokeWidthBorder;
canvas.DrawRect(0, y, Width, y + StrokeWidthBorder, GridPaint);
}
}
示例13: setBackground
private void setBackground()
{
LinearLayout player2layout = FindViewById<LinearLayout>(Resource.Id.player2layout);
if(_player2background != null)
{
_player2background.Recycle();
_player2background.Dispose();
}
// Create image
_player2background = Bitmap.CreateBitmap(player2layout.Width, player2layout.Height, Bitmap.Config.Argb8888);
Canvas backCanvas = new Canvas(_player2background);
// Background stroke paint
float strokeBorderWidth = (FindViewById<ButtonStroked>(Resource.Id.buttonMoveLeft)).Settings.StrokeBorderWidth;
int padding = (int)strokeBorderWidth/2 + Utils.GetPixelsFromDP(this, 5);
player2layout.SetPadding(padding, 0, 0, padding);
Paint strokeBackPaint = new Paint();
strokeBackPaint.Color = Utils.getAndroidColor(TetrisColor.Red);
strokeBackPaint.SetStyle(Paint.Style.Stroke);
strokeBackPaint.StrokeWidth = strokeBorderWidth/2;
strokeBackPaint.AntiAlias = true;
// Get rectangle
Rect local = new Rect();
player2layout.GetLocalVisibleRect(local);
RectF bounds = new RectF(local);
bounds.Left += strokeBorderWidth/2;
bounds.Bottom -= strokeBorderWidth/2;
bounds.Top -= strokeBorderWidth;
bounds.Right += strokeBorderWidth;
// Actually draw background
int radiusIn = (FindViewById<ButtonStroked>(Resource.Id.buttonMoveLeft)).Settings.RadiusIn;
int radiusOut = (FindViewById<ButtonStroked>(Resource.Id.buttonMoveLeft)).Settings.RadiusOut;
backCanvas.DrawRoundRect(bounds, radiusOut, radiusOut, strokeBackPaint);
// Use it as background
player2layout.SetBackgroundDrawable(new BitmapDrawable(_player2background));
backCanvas.Dispose();
strokeBackPaint.Dispose();
}
示例14: InitializeUI
//--------------------------------------------------------------
// PROTECTED METHODS
//--------------------------------------------------------------
protected bool InitializeUI()
{
_buttonLayout.SetMinimumHeight(Math.Max(_positiveButton.Height, _negativeButton.Height));
// Initialize background
if(_root.Width <= 0 || _root.Height <= 0)
return false;
if(_backgroundImage != null)
{
_backgroundImage.Recycle();
_backgroundImage.Dispose();
}
_backgroundImage = Bitmap.CreateBitmap(_root.Width, _root.Height, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(_backgroundImage);
Rect local = new Rect();
_root.GetLocalVisibleRect(local);
RectF bounds = new RectF(local);
bounds.Top += Builder.StrokeBorderWidth/2;
bounds.Left += Builder.StrokeBorderWidth/2;
bounds.Right -= Builder.StrokeBorderWidth/2;
bounds.Bottom -= Builder.StrokeBorderWidth/2;
// Background fill paint
Paint fillBackPaint = new Paint();
fillBackPaint.Color = Builder.FillColor;
fillBackPaint.AntiAlias = true;
// Background stroke paint
Paint strokeBackPaint = new Paint();
strokeBackPaint.Color = Builder.StrokeColor;
strokeBackPaint.SetStyle(Paint.Style.Stroke);
strokeBackPaint.StrokeWidth = Builder.StrokeBorderWidth;
strokeBackPaint.AntiAlias = true;
canvas.DrawRoundRect(bounds, Builder.RadiusOut, Builder.RadiusOut, strokeBackPaint);
canvas.DrawRoundRect(bounds, Builder.RadiusIn, Builder.RadiusIn, fillBackPaint);
_root.SetBackgroundDrawable(new BitmapDrawable(_backgroundImage));
canvas.Dispose();
strokeBackPaint.Dispose();
fillBackPaint.Dispose();
return true;
}
示例15: loadProfilePicture
private void loadProfilePicture(Guid contactId)
{
if (contactId != null) {
ContactDB cont = new ContactDB ();
if (contacts.ContainsKey (contactId))
cont = contacts [contactId];
byte[] imgdata = cont.ContactUser.Picture;
Bitmap original = BitmapFactory.DecodeByteArray (imgdata, 0, imgdata.Length);
Bitmap mask = Bitmap.CreateScaledBitmap (BitmapFactory.DecodeResource (Resources, Resource.Drawable.emptybackground), original.Width, original.Height, true);
Bitmap result = Bitmap.CreateBitmap (mask.Width, mask.Height, Bitmap.Config.Argb8888);
Canvas canv = new Canvas (result);
Paint paint = new Paint (PaintFlags.AntiAlias);
paint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.DstIn));
canv.DrawBitmap (original, 0, 0, null);
canv.DrawBitmap (mask, 0, 0, paint);
paint.SetXfermode (null);
RunOnUiThread (delegate {
ImageView pic = (ImageView)converse.FindViewWithTag (new Java.Lang.String ("profilepic_" + contactId.ToString ()));
pic.SetImageBitmap (result);
original.Dispose ();
mask.Dispose ();
paint.Dispose ();
canv.Dispose ();
result.Dispose ();
});
}
}