当前位置: 首页>>代码示例>>C#>>正文


C# Paint.GetTextBounds方法代码示例

本文整理汇总了C#中Android.Graphics.Paint.GetTextBounds方法的典型用法代码示例。如果您正苦于以下问题:C# Paint.GetTextBounds方法的具体用法?C# Paint.GetTextBounds怎么用?C# Paint.GetTextBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Android.Graphics.Paint的用法示例。


在下文中一共展示了Paint.GetTextBounds方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetBitmapMarker

        public Bitmap GetBitmapMarker(Context mContext, int resourceId, string text)
        {
            Resources resources = mContext.Resources;
            float scale = resources.DisplayMetrics.Density;
            Bitmap bitmap = BitmapFactory.DecodeResource(resources, resourceId);

            Bitmap.Config bitmapConfig = bitmap.GetConfig();

            // set default bitmap config if none
            if (bitmapConfig == null)
                bitmapConfig = Bitmap.Config.Argb8888;

            bitmap = bitmap.Copy(bitmapConfig, true);

            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint(PaintFlags.AntiAlias);
            paint.Color = global::Android.Graphics.Color.Black;
            paint.TextSize = ((int)(14 * scale));
            paint.SetShadowLayer(1f, 0f, 1f, global::Android.Graphics.Color.White);

            // draw text to the Canvas center
            Rect bounds = new Rect();
            paint.GetTextBounds(text, 0, text.Length, bounds);
            int x = (bitmap.Width - bounds.Width()) / 2;
            int y = (bitmap.Height + bounds.Height()) / 2 - 20;

            canvas.DrawText(text, x, y, paint);

            return bitmap;
        }
开发者ID:sgraphics,项目名称:BindableMapTest,代码行数:30,代码来源:ExtendedMapRenderer.cs

示例2: 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);
        }
开发者ID:rolfbjarne,项目名称:XamChess,代码行数:32,代码来源:GameView.cs

示例3: Draw

        public override void Draw(Canvas canvas, ICharSequence text, Int32 start, Int32 end, Single x, Int32 top, Int32 y, Int32 bottom, Paint paint)
        {
            ApplyCustomTypeFace(paint, _type);
            paint.GetTextBounds(_icon, 0, 1, TEXT_BOUNDS);
            canvas.Save();
            var baselineRatio = _baselineAligned ? 0f : BASELINE_RATIO;
            if (_rotate)
            {
                var rotation = (SystemClock.CurrentThreadTimeMillis() - _rotationStartTime) / (Single)ROTATION_DURATION * 360f;
                var centerX = x + TEXT_BOUNDS.Width() / 2f;
                var centerY = y - TEXT_BOUNDS.Height() / 2f + TEXT_BOUNDS.Height() * baselineRatio;
                canvas.Rotate(rotation, centerX, centerY);
            }

            canvas.DrawText(_icon, x - TEXT_BOUNDS.Left, y - TEXT_BOUNDS.Bottom + TEXT_BOUNDS.Height() * baselineRatio, paint);
            canvas.Restore();
        }
开发者ID:MuffPotter,项目名称:Xamarin.Plugins,代码行数:17,代码来源:CustomTypefaceSpan.cs

示例4: Draw

        public override void Draw(Canvas canvas, ICharSequence text, int start, int end, float x, int top, int y,
            int bottom, Paint paint)
        {
            ApplyCustomTypeFace(paint, _typeface);
            paint.GetTextBounds(_icon, 0, 1, TextBounds);
            canvas.Save();
            if (_rotate)
            {
                var rotation = (DateTimeHelpers.CurrentUnixTimeMillis() - _rotationStartTime)/(float) RotationDuration*
                               360f;
                var centerX = x + TextBounds.Width()/2f;
                var centerY = y - TextBounds.Height()/2f + TextBounds.Height()*BaselineRatio;
                canvas.Rotate(rotation, centerX, centerY);
            }

            canvas.DrawText(_icon, x - TextBounds.Left, y - TextBounds.Bottom + TextBounds.Height()*BaselineRatio,
                paint);
            canvas.Restore();
        }
开发者ID:PragmaticIT,项目名称:xiconify,代码行数:19,代码来源:CustomTypefaceSpan.cs

示例5: Draw

        public override void Draw(Canvas canvas, ICharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint)
        {
            ApplyCustomTypeFace(paint, type);
            paint.GetTextBounds(icon, 0, 1, TEXT_BOUNDS);
            canvas.Save();
            float baselineRatio = baselineAligned ? 0f : BASELINE_RATIO;
            if (rotate)
            {
                long time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                float rotation = (time - rotationStartTime) / (float)ROTATION_DURATION * 360f;
                float centerX = x + TEXT_BOUNDS.Width() / 2f;
                float centerY = y - TEXT_BOUNDS.Height() / 2f + TEXT_BOUNDS.Height() * baselineRatio;
                canvas.Rotate(rotation, centerX, centerY);
            }

            canvas.DrawText(icon,
                    x - TEXT_BOUNDS.Left,
                    y - TEXT_BOUNDS.Bottom + TEXT_BOUNDS.Height() * baselineRatio, paint);
            canvas.Restore();
        }
开发者ID:Mitch528,项目名称:IconifyXamarin,代码行数:20,代码来源:CustomTypefaceSpan.cs

示例6: MeasureText

        public Size MeasureText(string text, string fontFamily = null, double fontSize = 10, double fontWeight = 500)
        {
            if (string.IsNullOrEmpty(text))
            {
                return Size.Empty;
            }

            using (var paint = new Paint())
            {
                paint.AntiAlias = true;
                paint.TextSize = (float)fontSize;
                var bounds = new Rect();
                paint.GetTextBounds(text, 0, text.Length, bounds);
                // var width = paint.MeasureText(text);
                return new Size(bounds.Width(), bounds.Height());
            }
        }
开发者ID:jcw-,项目名称:sparrowtoolkit,代码行数:17,代码来源:CanvasRenderContext.cs

示例7: DrawText

        public void DrawText(Point p, string text, Color fill, string fontFamily = null, double fontSize = 10, double fontWeight = 500, double rotate = 0, HorizontalAlignment halign = HorizontalAlignment.Left, VerticalAlignment valign = VerticalAlignment.Top, Size? maxSize = new Size?())
        {
            using (var paint = new Paint())
            {
                paint.AntiAlias = true;
                paint.TextSize = (float)fontSize;
                paint.Color = fill;
                var bounds = new Rect();
                paint.GetTextBounds(text, 0, text.Length, bounds);

                float dx = 0;
                if (halign == HorizontalAlignment.Center)
                {
                    dx = -bounds.Width() / 2;
                }

                if (halign == HorizontalAlignment.Right)
                {
                    dx = -bounds.Width();
                }

                float dy = 0;
                if (valign == VerticalAlignment.Center)
                {
                    dy = +bounds.Height() / 2;
                }

                if (valign == VerticalAlignment.Top)
                {
                    dy = bounds.Height();
                }

                canvas.Save();
                canvas.Translate(dx, dy);
                canvas.Rotate((float)rotate);
                canvas.Translate((float)p.X, (float)p.Y);
                canvas.DrawText(text, 0, 0, paint);
                canvas.Restore();
            }
        }
开发者ID:jcw-,项目名称:sparrowtoolkit,代码行数:40,代码来源:CanvasRenderContext.cs

示例8: OnDraw

 protected override void OnDraw(Canvas canvas)
 {
     base.OnDraw (canvas);
                 //create an instance of class Paint, set color and font size
                 var textPaint = new Paint {
                         AntiAlias = true,
                         Color = _textColor,
                         TextSize = _textSize };
                 //In order to show text in a middle, we need to know its size
                 var bounds = new Rect ();
                 textPaint.GetTextBounds (_text, 0, _text.Length, bounds);
                 //Now we store font size in bounds variable and can calculate it's position
                 var x = (Width / 2) - bounds.CenterX ();
                 var y = (Height / 2) - bounds.CenterY ();
                 //drawing text with appropriate color and size in the center
                 canvas.DrawText (_text, x, y, textPaint);
 }
开发者ID:shuoguo,项目名称:cross-copy,代码行数:17,代码来源:ProgressBarX.cs

示例9: MeasureText

 public BasicRectangle MeasureText(string text, BasicRectangle rectangle, string fontFace, float fontSize)
 {
     var paint = new Paint
     {
         AntiAlias = true,
         TextSize = fontSize * Density
     };
     var rectText = new Rect();
     paint.GetTextBounds(text, 0, text.Length, rectText);
     return new BasicRectangle(rectText.Left, rectText.Top, rectText.Width(), rectText.Height());
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:11,代码来源:GraphicsContextWrapper.cs

示例10: DrawText

 public void DrawText(string text, BasicPoint point, BasicColor color, string fontFace, float fontSize)
 {
     var paint = new Paint
     {
         AntiAlias = true,
         Color = GenericControlHelper.ToColor(color),
         TextSize = fontSize * Density,
     };
     var boundsText = new Rect();
     paint.GetTextBounds(text, 0, text.Length, boundsText);
     _canvas.DrawText(text, point.X - boundsText.Left, point.Y - boundsText.Top, paint);
     //_canvas.DrawText(text, point.X, point.Y, paint);
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:13,代码来源:GraphicsContextWrapper.cs

示例11: Draw

		/// <Docs>The Canvas to which the View is rendered.</Docs>
		/// <summary>
		/// Draw the specified canvas.
		/// </summary>
		/// <param name="canvas">Canvas to draw onto.</param>
		public override void Draw(Canvas canvas)
		{
			BadgeImage image = (BadgeImage)Element;

			// Set color of icon
			if (Control.Drawable != null)
			{
				if (image.Selected)
				{
					Control.Drawable.SetColorFilter(filterColor);
				}
				else
				{
					Control.Drawable.SetColorFilter(filterGray);
				}
			}

			base.Draw(canvas);

			if (image.Number > 0)
			{
				using (Paint paint = new Paint())
				{
					paint.Color = image.Selected ? Xamarin.Forms.Color.Red.ToAndroid() : Xamarin.Forms.Color.Gray.ToAndroid();
					paint.StrokeWidth = 0f;
					paint.SetStyle(Paint.Style.FillAndStroke);

					// Calc text size
					paint.TextSize = (int)this.DipToPixel(16);
					paint.FakeBoldText = true;

					string text = image.Number.ToString();
					Rect textBounds = new Rect(0, 0, 0, 0);

					paint.GetTextBounds(text, 0, text.Length, textBounds);

					float textWidth = paint.MeasureText(text);
					float textHeight = textBounds.Height();

					float badgeWidth = textWidth + this.DipToPixel(9);
					float badgeHeight = textHeight + this.DipToPixel(9);

					if (badgeWidth < badgeHeight)
					{
						badgeWidth = badgeHeight;
					}

					double offsetX = (image.Bounds.Width - image.Bounds.Width) / 2;
					double offsetY = (image.Bounds.Height - image.Bounds.Height) / 2;

					float left = this.DipToPixel(image.Bounds.Width) - badgeWidth;
					float top = 1;
					float right = left + badgeWidth;
					float bottom = top + badgeHeight;
					float radius = (badgeHeight / 2f) - 1f;

					using (Path path = new Path())
					{
						canvas.DrawRoundRect(new RectF(left, top, left + badgeWidth, top + badgeHeight), radius, radius, paint);

						paint.Color = Xamarin.Forms.Color.White.ToAndroid();

						canvas.DrawText(image.Number.ToString(), left + ((badgeWidth - textWidth) / 2) - 1, bottom - ((badgeHeight - textHeight) / 2), paint);
					}
				}
			}
		}
开发者ID:Surfoo,项目名称:WF.Player,代码行数:72,代码来源:BadgeImageRenderer.cs

示例12: InitializeImages

        private void InitializeImages()
        {
            if(_pressedImage != null)
            {
                _pressedImage.Recycle();
                _pressedImage.Dispose();
            }
            if(_unpressedImage != null)
            {
                _unpressedImage.Recycle();
                _unpressedImage.Dispose();
            }

            _unpressedImage = Bitmap.CreateBitmap(Width, Settings.IsSquared ? Width : Height, Bitmap.Config.Argb8888);
            _pressedImage = Bitmap.CreateBitmap(Width, Settings.IsSquared ? Width : Height, Bitmap.Config.Argb8888);
            Canvas unpressedCanvas = new Canvas(_unpressedImage);
            Canvas pressedCanvas = new Canvas(_pressedImage);

            Settings.SetTextSize(ComplexUnitType.Px, Settings.TextSize == 0f ? Height * Settings.TextSizeRatio : Settings.TextSize);
            Settings.StrokeBorderWidth = Height * Settings.StrokeBorderWidthRatio;
            Settings.StrokeTextWidth = Height * Settings.StrokeTextWidthRatio;

            // Background fill paint
            Paint fillBackPaint = new Paint();
            fillBackPaint.Color = Settings.FillColor;
            fillBackPaint.AntiAlias = true;

            // Background stroke paint
            Paint strokeBackPaint = new Paint();
            strokeBackPaint.Color = Settings.StrokeColor;
            strokeBackPaint.SetStyle(Paint.Style.Stroke);
            strokeBackPaint.StrokeWidth = Settings.StrokeBorderWidth;
            strokeBackPaint.AntiAlias = true;

            // Text paint
            Paint textPaint = new Paint();
            textPaint.Color = Settings.IsTextStroked ? Settings.FillColor : Settings.StrokeColor;
            textPaint.TextAlign = Paint.Align.Center;
            textPaint.TextSize = Settings.TextSize;
            textPaint.SetTypeface(Settings.Typeface);
            textPaint.AntiAlias = true;

            // Text stroke paint
            Paint strokePaint = new Paint();
            strokePaint.Color = Settings.StrokeColor;
            strokePaint.TextAlign = Paint.Align.Center;
            strokePaint.TextSize = Settings.TextSize;
            strokePaint.SetTypeface(Settings.Typeface);
            strokePaint.SetStyle(Paint.Style.Stroke);
            strokePaint.StrokeWidth = Settings.StrokeTextWidth;
            strokePaint.AntiAlias = true;

            // Background bounds
            Rect local = new Rect();
            this.GetLocalVisibleRect(local);
            RectF bounds = new RectF(local);
            bounds.Top += Settings.StrokeBorderWidth/2;
            bounds.Left += Settings.StrokeBorderWidth/2;
            bounds.Right -= Settings.StrokeBorderWidth/2;
            bounds.Bottom -= Settings.StrokeBorderWidth/2;

            while(bounds.Top > Height)
            {
                bounds.Top -= Height;
            }
            while(bounds.Bottom > Height)
            {
                bounds.Bottom -= Height;
            }
            while(bounds.Left > Width)
            {
                bounds.Left -= Width;
            }
            while(bounds.Right > Width)
            {
                bounds.Right -= Width;
            }

            // Text location
            Rect r = new Rect();
            strokePaint.GetTextBounds(Text, 0, Text.Length, r);
            while(r.Width() + Settings.StrokeTextWidth >= bounds.Width())
            {
                Settings.SetTextSize(ComplexUnitType.Px, Settings.TextSize-1);
                textPaint.TextSize = Settings.TextSize;
                strokePaint.TextSize = Settings.TextSize;
                strokePaint.GetTextBounds(Text, 0, Text.Length, r);
            }

            float x=0, y=0;
            switch (Settings.Gravity)
            {
            case GravityFlags.Top:
                y = PaddingTop + r.Height()/2;
                break;
            case GravityFlags.Bottom:
                y = Height - r.Height()/2 - PaddingBottom;
                break;
            default:
                y = Height / 2f + r.Height() / 2f - r.Bottom;
//.........这里部分代码省略.........
开发者ID:lea-and-anthony,项目名称:Tetrim,代码行数:101,代码来源:ButtonStroked.cs

示例13: MeasureString

        public Size MeasureString(string text, Font font)
        {
            using (var p = new Paint(this.paint))
            using (var bounds = new Rect())
            using (var fm = p.GetFontMetrics())
            {
                p.TextSize = font.Size;
                p.SetTypeface(font.FontFamily.Typeface);
                p.SetStyle(Paint.Style.Stroke);

                p.GetTextBounds(text, 0, text.Length, bounds);
                var width = bounds.Width();
                var height = -fm.Top + fm.Bottom;

                return new SizeF(width, height).ToSize();
            }
        }
开发者ID:majorsilence,项目名称:System.Drawing.Wrappers,代码行数:17,代码来源:Graphics.Android.cs


注:本文中的Android.Graphics.Paint.GetTextBounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。