private void DrawAndGate(Canvas canvas, AndGate andGate) { float x = andGate.X; float y = andGate.Y; bool showPins = andGate.ShowPins; float w = andGate.Width; // element width float h = andGate.Height; // element height SetElementColor(andGate); // draw element shape canvas.DrawLine(x + 0f, y + 0f, x + w, y + 0f, elementPaint); canvas.DrawLine(x + w, y + 0f, x + w, y + h, elementPaint); canvas.DrawLine(x + w, y + h, x + 0f, y + h, elementPaint); canvas.DrawLine(x + 0f, y + h, x + 0f, y + 0f, elementPaint); // draw text in center of element shape string text = "&"; float textVerticalOffset = (textElementPaint.Descent() + textElementPaint.Ascent()) / 2f; canvas.DrawText(text, x + w / 2f, y + (h / 2f) - textVerticalOffset, textElementPaint); // draw element pins if (showPins == true) { DrawPins(canvas, andGate.Pins); } }
protected void DrawText(Canvas canvas, int column, int row, int year, int month, int day) { paint.TextSize = 30;//.SetTextSize(theme.sizeDay()); float startX = columnSize * column + (columnSize - paint.MeasureText(day + "")) / 2; float startY = rowSize * row + rowSize / 2 - (paint.Ascent() + paint.Descent()) / 2; paint.SetStyle(Paint.Style.Stroke); string des = IscalendarInfo(year, month, day); if (day == selDay) { //日期为选中的日期 if (!TextUtils.IsEmpty(des)) { //desc不为空的时候 int dateY = (int)startY; paint.Color = Android.Graphics.Color.SeaGreen; //.setColor(theme.colorSelectDay()); canvas.DrawText(day + "", startX, dateY, paint); paint.Color = Android.Graphics.Color.Black; //.setColor(theme.colorWeekday()); paint.TextSize = 18; //.SetTextSize(theme.sizeDesc()); int desX = (int)(columnSize * column + (columnSize - paint.MeasureText(des)) / 2); int desY = (int)(rowSize * row + rowSize * 0.9 - (paint.Ascent() + paint.Descent()) / 2); canvas.DrawText(des, desX, desY, paint); } else { //des为空的时候 paint.Color = Android.Graphics.Color.Orange; //.setColor(theme.colorSelectDay()); canvas.DrawText(day + "", startX, startY, paint); } } else if (day == currDay && currDay != selDay && currMonth == selMonth) { //今日的颜色,不是选中的时候 //正常月,选中其他日期,则今日为红色 paint.Color = Android.Graphics.Color.Red; //.setColor(theme.colorToday()); canvas.DrawText(day + "", startX, startY, paint); } else { if (!TextUtils.IsEmpty(des)) { //没选中,但是desc不为空 int dateY = (int)startY; paint.Color = Android.Graphics.Color.Black; //.setColor(theme.colorWeekday()); canvas.DrawText(day + "", startX, dateY, paint); paint.TextSize = 18; //.setTextSize(theme.sizeDesc()); paint.Color = Android.Graphics.Color.Red; //.setColor(theme.colorDesc()); int desX = (int)(columnSize * column + Math.Abs((columnSize - paint.MeasureText(des)) / 2)); int desY = (int)(startY + 20); canvas.DrawText(des, desX, desY, paint); } else { //des为空 paint.Color = Android.Graphics.Color.LawnGreen; //.SetColor(theme.colorWeekday()); canvas.DrawText(day + "", startX, startY, paint); } } }
private void Render(Canvas canvas, IText text) { var paint = new Paint() { Color = ToNativeColor(text.Foreground), AntiAlias = true, StrokeWidth = 1f, TextAlign = text.HorizontalAlignment == 0 ? Paint.Align.Left : text.HorizontalAlignment == 1 ? Paint.Align.Center : text.HorizontalAlignment == 2 ? Paint.Align.Right : Paint.Align.Center, TextSize = (float)text.Size, SubpixelText = true, }; double x = Math.Min(text.Point1.X, text.Point2.X); double y = Math.Min(text.Point1.Y, text.Point2.Y); double width = Math.Abs(text.Point2.X - text.Point1.X); double height = Math.Abs(text.Point2.Y - text.Point1.Y); float verticalSize = paint.Descent() + paint.Ascent(); float verticalOffset = text.VerticalAlignment == 0 ? 0.0f : text.VerticalAlignment == 1 ? verticalSize / 2.0f : text.VerticalAlignment == 2 ? verticalSize : verticalSize / 2.0f; canvas.DrawText( text.Text, (float)(x + width / 2.0), (float)(y + (height / 2.0) - verticalOffset), paint); }
internal static Bitmap RenderBitmap(IModel model, Func <int, int, Bitmap.Config, Bitmap> newBitmap) { using var paint = new Paint { TextSize = model.TextSize, Color = model.Color, TextAlign = Paint.Align.Left, AntiAlias = true, }; if (model.Typeface != null) { paint.SetTypeface(model.Typeface); } var width = (int)(paint.MeasureText(model.Glyph) + .5f); var baseline = (int)(-paint.Ascent() + .5f); var height = (int)(baseline + paint.Descent() + .5f); var bitmap = newBitmap(width, height, Bitmap.Config.Argb8888 !); using var canvas = new Canvas(bitmap); canvas.DrawText(model.Glyph, 0, baseline, paint); return(bitmap); }
private void DrawTextCentered(string text, float x, float y, Paint paint, Canvas canvas) { //float xPos = x - (paint.measureText(text)/2f); float yPos = (y - ((paint.Descent() + paint.Ascent()) / 2f)); canvas.DrawText(text, x, yPos, paint); }
static void DrawYLabels(Canvas canvas, float density, Paint bandsPaint, Paint textPaint, Line horizontal, Line vertical, IEnumerable <double> values) { textPaint.TextAlign = Paint.Align.Right; var numberOfSections = (int)Math.Ceiling(values.Max() / 100); var sectionWidth = (vertical.YStop - vertical.YStart) / numberOfSections; foreach (var v in Enumerable.Range(0, numberOfSections).Select(i => Tuple.Create(i * 100, i))) { var y = vertical.YStop - sectionWidth * v.Item2; canvas.DrawText( text: v.Item1.ToString(), x: vertical.XStart - 2 * density, y: y - (textPaint.Ascent() / 2f), paint: textPaint); if (v.Item2 % 2 > 0 && v.Item2 < numberOfSections) { canvas.DrawRect( left: horizontal.XStart, top: y - sectionWidth, right: horizontal.XStop, bottom: y, paint: bandsPaint); } } }
public Bitmap GetBitmap(string text) { Paint paint = new Paint(PaintFlags.AntiAlias); paint.TextSize = 15 * Context.Resources.DisplayMetrics.Density; paint.Color = Android.Graphics.Color.Black; paint.TextAlign = Paint.Align.Left; paint.StrokeWidth = 3; Rect bounds = new Rect(); paint.GetTextBounds(text, 0, text.Length, bounds); float baseline = -paint.Ascent(); // ascent() is negative int width = (int)(paint.MeasureText(text) + 0.5f) + 30; // round int height = (int)(baseline + paint.Descent() + 0.5f) + 15; Bitmap bitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(bitmap); canvas.DrawColor(Android.Graphics.Color.White); canvas.DrawText(text, 15, baseline + 7, paint); #region border Paint strokePaint = new Paint(); strokePaint.SetStyle(Paint.Style.Stroke); strokePaint.Color = Android.Graphics.Color.Gray; strokePaint.StrokeWidth = 4; RectF r = new RectF(0, 0, width, height); canvas.DrawRect(r, strokePaint); #endregion return(doHighlightImage(bitmap)); }
//public override void Draw(Canvas canvas) //{ // Log.WriteLine(LogPriority.Info, "Test", "Draw"); // //base.Draw(canvas); //} protected override void OnDraw(Canvas canvas) { int width = this.Width; // // getWidth(); int height = this.Height; // getHeight(); //进行画上下线 paint.SetStyle(Paint.Style.Stroke); paint.Color = mTopLineColor; paint.StrokeWidth = mStrokeWidth;//.setStrokeWidth(mStrokeWidth); canvas.DrawLine(0, 0, width, 0, paint); //画下横线 paint.Color = mBottomLineColor;//SetColor(mBottomLineColor); canvas.DrawLine(0, height, width, height, paint); paint.SetStyle(Paint.Style.Fill); paint.TextSize = mWeekSize * mDisplayMetrics.ScaledDensity; int columnWidth = width / 7; for (int i = 0; i < weekString.Length; i++) { String text = weekString[i]; int fontWidth = (int)paint.MeasureText(text); int startX = columnWidth * i + (columnWidth - fontWidth) / 2; int startY = (int)(height / 2 - (paint.Ascent() + paint.Descent()) / 2); if (text.IndexOf("日") > -1 || text.IndexOf("六") > -1) { paint.Color = mWeekendColor; } else { paint.Color = mWeedayColor; } canvas.DrawText(text, startX, startY, paint); } }
public Task <Bitmap> LoadImageAsync( ImageSource imagesource, Context context, CancellationToken cancelationToken = default(CancellationToken)) { Bitmap image = null; var fontsource = imagesource as FontImageSource; if (fontsource != null) { var paint = new Paint { TextSize = TypedValue.ApplyDimension(ComplexUnitType.Dip, (float)fontsource.Size, context.Resources.DisplayMetrics), Color = (fontsource.Color != Color.Default ? fontsource.Color : Color.White).ToAndroid(), TextAlign = Paint.Align.Left, AntiAlias = true, }; paint.SetTypeface(fontsource.FontFamily.ToTypeFace()); var width = (int)(paint.MeasureText(fontsource.Glyph) + .5f); var baseline = (int)(-paint.Ascent() + .5f); var height = (int)(baseline + paint.Descent() + .5f); image = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888); var canvas = new Canvas(image); canvas.DrawText(fontsource.Glyph, 0, baseline, paint); } return(Task.FromResult(image)); }
private Bitmap LoadImage(ImageSource imagesource, Context context) { Bitmap image = null; if (imagesource is IconImageSource iconsource && FontRegistry.HasFont(iconsource.Name, out var font)) { var paint = new Paint { TextSize = TypedValue.ApplyDimension(ComplexUnitType.Dip, (float)iconsource.Size, context.Resources.DisplayMetrics), Color = (iconsource.Color != Color.Default ? iconsource.Color : Color.White).ToAndroid(), TextAlign = Paint.Align.Left, AntiAlias = true, }; using (var typeface = Typeface.CreateFromAsset(context.ApplicationContext.Assets, font.FontFileName)) paint.SetTypeface(typeface); paint.SetTypeface(font.Alias.ToTypeFace()); var glyph = font.GetGlyph(iconsource.Name); var width = (int)(paint.MeasureText(glyph) + .5f); var baseline = (int)(-paint.Ascent() + .5f); var height = (int)(baseline + paint.Descent() + .5f); image = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888); var canvas = new Canvas(image); canvas.DrawText(glyph, 0, baseline, paint); } return(image); }
public AndroidFontMetrics(Paint paint) { _widths = new float[NumWidths]; paint.GetTextWidths(_chars, 0, NumWidths, _widths); Ascent = (int)(Math.Abs(paint.Ascent()) + 0.5f); Descent = (int)(paint.Descent() / 2 + 0.5f); Height = Ascent; }
private Rect CalcBounds(int index, Paint paint) { var bounds = new Rect(); var title = GetTitle(index); bounds.Right = (int)paint.MeasureText(title); bounds.Bottom = (int)(paint.Descent() - paint.Ascent()); return(bounds); }
/** * Calculate the bounds for a view's title * * @param index * @param paint * @return */ private RectF CalcBounds(int index, Paint paint) { //Calculate the text bounds RectF bounds = new RectF(); bounds.Right = paint.MeasureText(mTitleProvider.GetTitle(index)); bounds.Bottom = paint.Descent() - paint.Ascent(); return(bounds); }
public void DrawText(FormattedText formattedText, Point point, Rect?clipRect) { var paint = new Paint(); paint.TextSize = formattedText.FontSize; paint.Color = formattedText.Brush.Color.ToAndroid(); paint.AntiAlias = true; var offset = -paint.Ascent(); canvas.DrawText(formattedText.Text, (float)point.X, (float)(point.Y + offset), paint); }
public AndroidFontMetrics(Paint paint) { _widths = new float[NumWidths]; paint.GetTextWidths(_chars, 0, NumWidths, _widths); //Ascent = (int)(Math.Abs (paint.Ascent ()) + 0.5f); //zu weit oben //Ascent = (int)(Math.Abs(paint.Ascent()) + 4.5f); //zu weit unten Ascent = (int)(Math.Abs(paint.Ascent()) + 2.5f); //Descent = (int)(paint.Descent() / 2 + 0.5f); Descent = (int)(paint.Descent() / 2 + 5.5f); Height = Ascent; }
protected override void OnDraw(Android.Graphics.Canvas canvas) { base.OnDraw(canvas); var _red = new Paint(); _red.SetStyle(Paint.Style.Fill); _red.SetARGB(255, 255, 0, 0); var _green = new Paint(); _green.SetStyle(Paint.Style.Fill); _green.SetARGB(255, 0, 255, 0); int presetsDrawn = 1; for (int c = 0; c < _columns; c++) { var row = ((float)_presets / (float)_columns); var rows = Math.Round(row, MidpointRounding.AwayFromZero); for (int r = 0; r < rows; r++) { var x = _columnWidth / 2 + _columnWidth * c; var y = _rowHeight / 2 + _rowHeight * r; var radius = _rowHeight / 2; var diameter = (_rowHeight / 4) * 3; var xDrawable = (x) - (diameter / 2); var yDrawable = (y) - (diameter / 2); radius /= 2; if (presetsDrawn <= _presets) { //Draw Buttons if (_selectedPreset == GetPresetFromColumnAndRow(c, r)) { white.SetBounds(xDrawable, yDrawable + _padding, xDrawable + diameter, yDrawable + _padding + diameter); white.Draw(canvas); } else { green.SetBounds(xDrawable, yDrawable + _padding, xDrawable + diameter, yDrawable + _padding + diameter); green.Draw(canvas); } //Draw Text var text = GetPresetFromColumnAndRow(c, r).ToString(); var offset = ((textPaint.Descent() + textPaint.Ascent()) / 2); canvas.DrawText(text, x, y - offset + _padding, textPaint); presetsDrawn++; } } } }
public static Bitmap getCircleBitmapWithText(Context context, string text, int bgColor, int textColor) { int width = (int)context.Resources.GetDimension(Resource.Dimension.chip_height); var output = Bitmap.CreateBitmap(width, width, Bitmap.Config.Argb8888); using var canvas = new Canvas(output); var paint = new Paint(); var textPaint = new Paint(); var rect = new Rect(0, 0, width, width); var rectF = new RectF(rect); paint.AntiAlias = true; canvas.DrawARGB(0, 0, 0, 0); paint.Color = new Color(bgColor); canvas.DrawOval(rectF, paint); textPaint.Color = new Color(textColor); textPaint.StrokeWidth = 30; textPaint.TextSize = 50; paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcOver)); textPaint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcAtop)); int xPos; int yPos; if (text.Length == 1) { xPos = (int)((canvas.Width / 1.9f) + ((textPaint.Descent() + textPaint.Ascent()) / 2f)); yPos = (int)((canvas.Height / 2f) - ((textPaint.Descent() + textPaint.Ascent()) / 2f)); } else { xPos = (int)((canvas.Width / 2.7f) + ((textPaint.Descent() + textPaint.Ascent()) / 2f)); yPos = (int)((canvas.Height / 2f) - ((textPaint.Descent() + textPaint.Ascent()) / 2f)); } canvas.DrawBitmap(output, rect, rect, paint); canvas.DrawText(text, xPos, yPos, textPaint); return(output); }
protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime) { if (Element is CounterIcon counterIcon && counterIcon.Counter != 0) { try { //Add Focus var paint = new Paint { Color = Android.Graphics.Color.Gray }; paint.SetStyle(Paint.Style.Fill); canvas.DrawCircle(canvas.Width / 2, canvas.Height / 2, canvas.Width / 2, paint); canvas.Save(); //Add image var result = base.DrawChild(canvas, child, drawingTime); //canvas.Restore(); //Add Circle paint = new Paint { Color = Android.Graphics.Color.Red }; paint.SetStyle(Paint.Style.Fill); canvas.DrawCircle(canvas.Width * 0.75f, canvas.Height / 4, canvas.Width / 4, paint); canvas.Save(); //Add number var number = counterIcon.Counter < 10 ? $" {counterIcon.Counter} " : $"{counterIcon.Counter}"; var textSize = 8; paint = new Paint(PaintFlags.AntiAlias) { TextAlign = Paint.Align.Center, TextSize = PixelsFromDp(textSize), Color = Android.Graphics.Color.White }; var space = (paint.Descent() + paint.Ascent()) / 2; var horizontalSpace = paint.MeasureText(number, 0, 2) / 2; canvas.DrawText(number, canvas.Width * 0.75f, canvas.Height / 4 - space, paint); canvas.Save(); paint.Dispose(); return(result); } catch { return(base.DrawChild(canvas, child, drawingTime)); } } return(base.DrawChild(canvas, child, drawingTime)); }
public Cell(int dayOfMon, Rect rect, float textSize, bool bold) { mDayOfMonth = dayOfMon; mBound = rect; mPaint.TextSize = textSize; mPaint.Color = Color.Black; if (bold) { mPaint.FakeBoldText = true; } dx = (int)mPaint.MeasureText(string.Format("{0}", mDayOfMonth)) / 2; dy = (int)(-mPaint.Ascent() + mPaint.Descent()) / 2; }
public AndroidFontMetrics(Font f, Paint paint) { var tf = f.IsBold ? Typeface.DefaultBold : Typeface.Default; Typeface = tf; paint.SetTypeface(tf); paint.TextSize = f.Size; _widths = new float[NumWidths]; paint.GetTextWidths(_chars, 0, NumWidths, _widths); Ascent = (int)(Math.Abs(paint.Ascent()) + 0.5f); Descent = (int)(paint.Descent() / 2 + 0.5f); Height = Ascent; }
private void ShowInfoText(Canvas canvas, string text) { var lines = text.Split("\n"); float textHeight = _textPaint.Descent() - _textPaint.Ascent(); float x = canvas.Width / 2f; float y = textHeight; canvas.DrawRect(0, 0, canvas.Width, (lines.Length + 3) * textHeight, _backgroundPaint); foreach (var line in lines) { y += textHeight; canvas.DrawText(line, x, y, _textPaint); } }
protected override void OnDraw(Canvas canvas) { InitSize(); daysString = new int[6, 7]; mPaint.TextSize = mDaySize * mDisplayMetrics.ScaledDensity;//.scaledDensity; string dayString; int mMonthDays = DateUtils.getMonthDays(mSelYear, mSelMonth); int weekNumber = DateUtils.getFirstDayWeek(mSelYear, mSelMonth); Log.WriteLine(LogPriority.Info, "DateView", "DateView:" + mSelMonth + "月1号周" + weekNumber);//.d("DateView", "DateView:" + mSelMonth + "月1号周" + weekNumber); for (int day = 0; day < mMonthDays; day++) { dayString = (day + 1) + ""; int column = (day + weekNumber - 1) % 7; int row = (day + weekNumber - 1) / 7; daysString[row, column] = day + 1; int startX = (int)(mColumnSize * column + (mColumnSize - mPaint.MeasureText(dayString)) / 2); int startY = (int)(mRowSize * row + mRowSize / 2 - (mPaint.Ascent() + mPaint.Descent()) / 2); if (dayString.Equals(mSelDay + "")) { //绘制背景色矩形 int startRecX = mColumnSize * column; int startRecY = mRowSize * row; int endRecX = startRecX + mColumnSize; int endRecY = startRecY + mRowSize; mPaint.Color = mSelectBGColor;//.SetColor(mSelectBGColor); canvas.DrawRect(startRecX, startRecY, endRecX, endRecY, mPaint); //记录第几行,即第几周 weekRow = row + 1; } //绘制事务圆形标志 DrawCircle(row, column, mSelYear, mSelMonth, day + 1, canvas); if (dayString.Equals(mSelDay + "")) { mPaint.Color = mSelectDayColor; } else if (dayString.Equals(mCurrDay + "") && mCurrDay != mSelDay && mCurrMonth == mSelMonth && mCurrYear == mSelYear) { //正常月,选中其他日期,则今日为红色 mPaint.Color = mCurrentColor; } else { mPaint.Color = mDayColor; } canvas.DrawText(dayString, startX, startY, mPaint); } }
public Bitmap textAsBitmap(String text, float textSize, Color textColor, out int width) { Paint paint = new Paint(PaintFlags.AntiAlias); paint.TextSize = textSize; paint.Color = textColor; paint.TextAlign = Paint.Align.Left; float baseline = -paint.Ascent(); // ascent() is negative width = (int)(paint.MeasureText(text) + 0.5f); // round int height = (int)(baseline + paint.Descent() + 0.5f); Bitmap image = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(image); canvas.DrawText(text, 0, baseline, paint); return(image); }
public Bitmap stringToBitmap(string input) { Paint paint = new Paint(PaintFlags.AntiAlias); paint.TextSize = 200; paint.Color = Color.Black; paint.TextAlign = Paint.Align.Left; float baseline = -paint.Ascent(); // ascent() is negative int width = (int)(paint.MeasureText(input) + 0.5f); // round int height = (int)(baseline + paint.Descent() + 0.5f); Bitmap image = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888); image.EraseColor(Color.White); Canvas canvas = new Canvas(image); canvas.DrawText(input, 0, baseline, paint); return(image); }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); float delta = Math.Max(finishedStrokeWidth, unfinishedStrokeWidth); _finishedOuterRect.Set(delta, delta, Width - delta, Height - delta); _unfinishedOuterRect.Set(delta, delta, Width - delta, Height - delta); float innerCircleRadius = (Width - Math.Min(finishedStrokeWidth, unfinishedStrokeWidth) + Math.Abs(finishedStrokeWidth - unfinishedStrokeWidth)) / 2f; canvas.DrawCircle(Width / 2.0f, Height / 2.0f, innerCircleRadius, _innerCirclePaint); canvas.DrawArc(_finishedOuterRect, getStartingDegree(), getProgressAngle(), false, _finishedPaint); canvas.DrawArc(_unfinishedOuterRect, getStartingDegree() + getProgressAngle(), 360 - getProgressAngle(), false, _unfinishedPaint); if (showText) { String text = this.text != null ? this.text : prefixText + progress + suffixText; if (!TextUtils.IsEmpty(text)) { float textHeight = _textPaint.Descent() + _textPaint.Ascent(); canvas.DrawText(text, (Width - _textPaint.MeasureText(text)) / 2.0f, (Width - textHeight) / 2.0f, _textPaint); } if (!TextUtils.IsEmpty(getInnerBottomText())) { _innerBottomTextPaint.TextSize = innerBottomTextSize; float bottomTextBaseline = Height - innerBottomTextHeight - (_textPaint.Descent() + _textPaint.Ascent()) / 2; canvas.DrawText(getInnerBottomText(), (Width - _innerBottomTextPaint.MeasureText(getInnerBottomText())) / 2.0f, bottomTextBaseline, _innerBottomTextPaint); } } if (attributeResourceId != 0) { Bitmap bitmap = BitmapFactory.DecodeResource(Resources, attributeResourceId); canvas.DrawBitmap(bitmap, (Width - bitmap.Width) / 2.0f, (Height - bitmap.Height) / 2.0f, null); } }
partial void drawHourLines(Canvas canvas) { canvas.DrawLine(verticalLineLeftMargin, 0f, verticalLineLeftMargin, maxHeight, linesPaint); var timeLinesYsToDraw = timeLinesYs; var hourLabelYsToDraw = hoursYs; for (var hour = 1; hour < timeLinesYsToDraw.Length; hour++) { var hourTop = hourLabelYsToDraw[hour] + linesPaint.Ascent(); var hourBottom = hourLabelYsToDraw[hour] + linesPaint.Descent(); if (!(hourBottom > scrollOffset) || !(hourTop - scrollOffset < Height)) { continue; } canvas.DrawLine(timeSliceStartX, timeLinesYsToDraw[hour], Width, timeLinesYsToDraw[hour], linesPaint); canvas.DrawText(hours[hour], hoursX, hourLabelYsToDraw[hour], hoursLabelPaint); } }
private Bitmap MakeFpsOverlay(Paint p, string text) { var b = new Rect(); p.GetTextBounds(text, 0, text.Length, b); var bwidth = b.Width() - 2; var bheight = b.Height() - 2; var bm = Bitmap.CreateBitmap(bwidth, bheight, Bitmap.Config.Argb8888); var c = new Canvas(bm); var obc = System.Drawing.Color.FromArgb(overlayBackgroundColor); p.SetARGB(obc.A, obc.R, obc.G, obc.B); c.DrawRect(0, 0, bwidth, bheight, p); var otc = System.Drawing.Color.FromArgb(overlayTextColor); p.SetARGB(otc.A, otc.R, otc.G, otc.B); c.DrawText(text, -b.Left + 1, (bheight / 2) - ((p.Ascent() + p.Descent()) / 2) + 1, p); return(bm); }
public static Bitmap WeatherIconToBitmap(Context context, String text, int textSize, Color textColor) { Paint paint = new Paint(PaintFlags.AntiAlias); Typeface weathericons = ResourcesCompat.GetFont(context, Resource.Font.weathericons); paint.SubpixelText = true; paint.SetTypeface(weathericons); paint.SetStyle(Paint.Style.Fill); paint.Color = textColor; paint.TextSize = textSize; paint.TextAlign = Paint.Align.Left; float baseline = -paint.Ascent(); int width = (int)(paint.MeasureText(text) + 0.5f); int height = (int)(baseline + paint.Descent() + 0.5f); Bitmap bmp = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888); Canvas myCanvas = new Canvas(bmp); myCanvas.DrawText(text, 0, baseline, paint); return(bmp); }
protected override void OnDraw(Canvas canvas) { var mPaint = new Paint(PaintFlags.FilterBitmap | PaintFlags.Dither | PaintFlags.AntiAlias) { Dither = true, Color = Color.Gray }; mPaint.SetStyle(Paint.Style.Stroke); mPaint.StrokeWidth = 2; //Circle float mouthInset = _radius / 3f; _arcBounds.Set(mouthInset, mouthInset, _radius * 2 - mouthInset, _radius * 2 - mouthInset); canvas.DrawArc(_arcBounds, 270f, 360, false, mPaint); //Arc mPaint.Color = Color.ParseColor("#33b5e5"); mPaint.StrokeWidth = 15; float sweep = 360 * _progress * 0.01f; canvas.DrawArc(_arcBounds, 0, sweep, false, mPaint); //Progress Text mPaint.TextSize = 50; mPaint.StrokeWidth = 4; mPaint.TextAlign = Paint.Align.Center; float textHeight = mPaint.Descent() - mPaint.Ascent(); float textOffset = (textHeight / 2) - mPaint.Descent(); canvas.DrawText(_progress + "%", _arcBounds.CenterX(), _arcBounds.CenterY() + textOffset, mPaint); }
public override void Draw(Canvas canvas, ICharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { var bounds = new Rect(); paint.GetTextBounds(text.ToString(), start, end, bounds); const int strokeWidth = 3; var previousStrokeWidth = paint.StrokeWidth; var rect = new RectF(margin + x, top + strokeWidth, margin + x + padding + bounds.Width() + padding, top + tokenHeight); paint.StrokeWidth = strokeWidth; paint.Color = backgroundColor; paint.SetStyle(shouldStrokeOnly ? Paint.Style.Stroke : paint.GetStyle()); canvas.DrawRoundRect(rect, cornerRadius, cornerRadius, paint); paint.Color = textColor; paint.StrokeWidth = previousStrokeWidth; paint.SetStyle(Paint.Style.FillAndStroke); canvas.DrawText(text, start, end, x + padding / 2.0f + margin - strokeWidth, rect.CenterY() - (paint.Descent() + paint.Ascent()) / 2, paint); }