本文整理汇总了C#中Paint类的典型用法代码示例。如果您正苦于以下问题:C# Paint类的具体用法?C# Paint怎么用?C# Paint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Paint类属于命名空间,在下文中一共展示了Paint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawEllipse
// assumptions for pixel snapping:
// - the drawing context itself is pixel snapped
// - all strokes have same thickness
// - the thickness is a whole number
#region ELLIPSES
/// <summary>See <c>WpfExtensions</c> for details.</summary>
public static void DrawEllipse(DrawingContext dc, Paint paint, Point center, double radiusX, double radiusY, bool snapToPixel) {
// get brush and stroke resources
if (paint == null) return;
var fill = paint.Fill;
var hasFill = (fill != null);
var strokes = paint.GetStrokePens().ToArray();
var numStrokes = strokes.Length;
if (!hasFill && numStrokes == 0) return;
var halfThickness = Math.Round(numStrokes > 0? strokes[0].Thickness : 0.0) / 2;
if (snapToPixel) {
center = new Point(center.X + halfThickness, center.Y + halfThickness);
}
if (numStrokes > 0) {
for (var i = 0; i < numStrokes - 1; i++) {
dc.DrawEllipse(null, strokes[i], center, radiusX, radiusY);
radiusX = (radiusX - 2 * halfThickness).Max(0);
radiusY = (radiusY - 2 * halfThickness).Max(0);
}
dc.DrawEllipse(fill, strokes[numStrokes - 1], center, radiusX, radiusY);
} else {
dc.DrawEllipse(fill, null, center, radiusX, radiusY);
}
}
示例2: SlidingTabStrip1
public SlidingTabStrip1(Context context, IAttributeSet attrs)
: base(context, attrs)
{
SetWillNotDraw(false);
float density = Resources.DisplayMetrics.Density;
TypedValue outValue = new TypedValue();
context.Theme.ResolveAttribute(Android.Resource.Attribute.ColorForeground, outValue, true);
int themeForeGround = outValue.Data;
mDefaultBottomBorderColor = SetColorAlpha(themeForeGround, DEFAULT_BOTTOM_BORDER_COLOR_ALPHA);
mDefaultTabColorizer = new SimpleTabColorizer1();
mDefaultTabColorizer.IndicatorColors = INDICATOR_COLORS;
mDefaultTabColorizer.DividerColors = DIVIDER_COLORS;
mBottomBorderThickness = (int)(DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density);
mBottomBorderPaint = new Paint();
mBottomBorderPaint.Color = GetColorFromInteger(0xC5C5C5); //Gray
mSelectedIndicatorThickness = (int)(SELECTED_INDICATOR_THICKNESS_DIPS * density);
mSelectedIndicatorPaint = new Paint();
mDividerHeight = DEFAULT_DIVIDER_HEIGHT;
mDividerPaint = new Paint();
mDividerPaint.StrokeWidth = (int)(DEFAULT_DIVIDER_THICKNESS_DIPS * density);
}
示例3: CircleImageView
public CircleImageView(Context context, IAttributeSet attrs, int defStyle)
: base(context, attrs, defStyle)
{
// init paint
paint = new Paint();
paint.AntiAlias = true;
paintBorder = new Paint();
paintBorder.AntiAlias = true;
// load the styled attributes and set their properties
TypedArray attributes = context.ObtainStyledAttributes(attrs, Resource.Styleable.CircularImageView, defStyle, 0);
if (attributes.GetBoolean(Resource.Styleable.CircularImageView_border, true))
{
int defaultBorderSize = (int)(4 * context.Resources.DisplayMetrics.Density+ 0.5f);
BorderWidth = attributes.GetDimensionPixelOffset(Resource.Styleable.CircularImageView_border_width, defaultBorderSize);
BorderColor = attributes.GetColor(Resource.Styleable.CircularImageView_border_color, Color.White);
}
if (attributes.GetBoolean(Resource.Styleable.CircularImageView_shadow, false))
{
addShadow();
}
}
示例4: Initialize
void Initialize ()
{
mPaint = new Paint ();
mPaint.Color = Color.Black;
mPaint.AntiAlias = true;
mPaint.SetStyle (Paint.Style.Fill);
}
示例5: 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;
}
}
示例6: MapPlotter
// Tile tile;
public MapPlotter(int size)
{
this.size = size;
defaultPaint = new Paint();
defaultPaint.Fill = PlotterHelper.DEFAULT_COLOR;
roadPaint = new Paint();
roadPaint.StrokeCap = PenLineCap.Round;
roadBorderPaint = new Paint();
roadBorderPaint.Stroke = PlotterHelper.ROAD_BORDER_COLOR;
roadBorderPaint.StrokeCap = PenLineCap.Round;
grassPaint = new Paint();
grassPaint.Fill = PlotterHelper.NATURE_GRASS_COLOR;
waterPaint = new Paint();
waterPaint.Fill = PlotterHelper.NATURE_WATER_COLOR;
riverPaint = new Paint();
riverPaint.Stroke = PlotterHelper.NATURE_RIVER_COLOR;
riverPaint.StrokeCap = PenLineCap.Round;
buildingPaint = new Paint();
}
示例7: 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);
}
}
示例8: BezelImageView
public BezelImageView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
{
// Attribute initialization
var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.BezelImageView, defStyle, 0);
mMaskDrawable = a.GetDrawable(Resource.Styleable.BezelImageView_maskDrawable);
if (mMaskDrawable == null) {
mMaskDrawable = Resources.GetDrawable(Resource.Drawable.bezel_mask);
}
mMaskDrawable.Callback = this;
mBorderDrawable = a.GetDrawable(Resource.Styleable.BezelImageView_borderDrawable);
if (mBorderDrawable == null) {
mBorderDrawable = Resources.GetDrawable(Resource.Drawable.bezel_border);
}
mBorderDrawable.Callback = this;
a.Recycle();
// Other initialization
mMaskedPaint = new Paint();
mMaskedPaint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcAtop));
mCopyPaint = new Paint();
}
示例9: GetRoundedCornerBitmap
// If you would like to create a circle of the image set pixels to half the width of the image.
internal static Bitmap GetRoundedCornerBitmap(Bitmap bitmap, int pixels)
{
Bitmap output = null;
try
{
output = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(output);
Color color = new Color(66, 66, 66);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
RectF rectF = new RectF(rect);
float roundPx = pixels;
paint.AntiAlias = true;
canvas.DrawARGB(0, 0, 0, 0);
paint.Color = color;
canvas.DrawRoundRect(rectF, roundPx, roundPx, paint);
paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
canvas.DrawBitmap(bitmap, rect, rect, paint);
}
catch (System.Exception err)
{
System.Console.WriteLine ("GetRoundedCornerBitmap Error - " + err.Message);
}
return output;
}
示例10: SampleView
public SampleView (Context context) : base (context)
{
Focusable = true;
mPaint = new Paint ();
mPaint.AntiAlias = true;
}
示例11: Draw
public override void Draw(Android.Graphics.Canvas canvas)
{
base.Draw (canvas);
Paint mBgPaints = new Paint ();
mBgPaints.AntiAlias = true;
mBgPaints.SetStyle (Paint.Style.Fill);
mBgPaints.Color = Color.Blue;
mBgPaints.StrokeWidth = 0.5f;
Paint tPaint = new Paint ();
tPaint.Alpha = 0;
canvas.DrawColor (tPaint.Color);
RectF mOvals = new RectF (40, 40, layout.MeasuredWidth - 40, layout.MeasuredHeight - 40);
decimal total = 0;
foreach (SecuritiesViewModel.PieChartValue value in securitiesViewModel.DataForPieChart ()) {
total += value.amount;
}
if (total == 0) {
return;
}
decimal degressPerAmount = 360 / total;
decimal currentAngle = 0;
foreach (SecuritiesViewModel.PieChartValue value in securitiesViewModel.DataForPieChart ()) {
canvas.DrawArc (mOvals, (float)currentAngle, (float)(degressPerAmount * value.amount), true, mBgPaints);
currentAngle += (degressPerAmount * value.amount);
mBgPaints.SetARGB (255, new Random ().Next (256), new Random ().Next (256), new Random ().Next (256));
}
}
示例12: applyFilterElements
public void applyFilterElements(Paint pPaint) {
this.mSVGAttributes.getFloatAttribute(SVGConstants.ATTRIBUTE_X, true);
List<ISVGFilterElement> svgFilterElements = this.mSVGFilterElements;
for(int i = 0; i < svgFilterElements.Count; i++) {
svgFilterElements[i].Apply(pPaint);
}
}
示例13: test_alphagradients
static void test_alphagradients (Canvas canvas)
{
canvas.translate (20, 10);
RectF r = new RectF (10, 10, 410, 30);
Paint p = new Paint (), p2 = new Paint ();
p2.setStyle (Paint.Style.STROKE);
using (Shader shader = setgrad (r, 0xFF00FF00, 0x0000FF00))
p.setShader (shader);
canvas.drawRect (r, p);
canvas.drawRect (r, p2);
r.offset (0, r.height () + 4);
using (Shader shader = setgrad(r, 0xFF00FF00, 0x00000000))
p.setShader (shader);
canvas.drawRect (r, p);
canvas.drawRect (r, p2);
r.offset (0, r.height () + 4);
using (Shader shader = setgrad(r, 0xFF00FF00, 0x00FF0000))
p.setShader (shader);
canvas.drawRect (r, p);
canvas.drawRect (r, p2);
}
示例14: ApplyCustomTypeFace
private static void ApplyCustomTypeFace(Paint paint, Typeface tf, Android.Graphics.Color color)
{
int oldStyle;
Typeface old = paint.Typeface;
if (old == null)
{
oldStyle = 0;
}
else
{
oldStyle = (int)old.Style;
}
int fake = oldStyle & ~(int)tf.Style;
if ((fake & (int)TypefaceStyle.Bold) != 0)
{
paint.FakeBoldText = true;
}
if ((fake & (int)TypefaceStyle.Italic) != 0)
{
paint.TextSkewX = -0.25f;
}
paint.SetARGB(color.A, color.R, color.G, color.B);
paint.SetTypeface(tf);
}
示例15: Draw
public override void Draw(Android.Graphics.Canvas canvas)
{
base.Draw(canvas);
var rect = new RectF(0,0,300,300);
switch (TheShape)
{
case Shape.Circle:
canvas.DrawOval(rect, new Paint() { Color = Color.Aqua });
break;
case Shape.Square:
canvas.DrawRect(rect, new Paint() { Color = Color.Red });
break;
case Shape.Triangle:
var path = new Path();
path.MoveTo(rect.CenterX(), 0);
path.LineTo(0, rect.Height());
path.LineTo(rect.Width(), rect.Height());
path.Close();
var paint = new Paint() {Color = Color.Magenta};
paint.SetStyle(Paint.Style.Fill);
canvas.DrawPath(path, paint);
break;
default:
throw new ArgumentOutOfRangeException();
}
}