當前位置: 首頁>>代碼示例>>C#>>正文


C# SKPaint.MeasureText方法代碼示例

本文整理匯總了C#中SkiaSharp.SKPaint.MeasureText方法的典型用法代碼示例。如果您正苦於以下問題:C# SKPaint.MeasureText方法的具體用法?C# SKPaint.MeasureText怎麽用?C# SKPaint.MeasureText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SkiaSharp.SKPaint的用法示例。


在下文中一共展示了SKPaint.MeasureText方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: MeasureTextSample

		public static void MeasureTextSample (SKCanvas canvas, int width, int height)
		{
			canvas.DrawColor (SKColors.White);

			using (var paint = new SKPaint ()) {
				paint.TextSize = 64.0f;
				paint.IsAntialias = true;
				paint.Color = new SKColor (0x42, 0x81, 0xA4);
				paint.TextEncoding = SKTextEncoding.Utf32;

				canvas.DrawText ("Skia (UTF-32)", 0, 64.0f, paint);

				var bounds = new SKRect();
				paint.MeasureText ("Skia (UTF-32)", ref bounds);
				bounds.Top += 64.0f;
				bounds.Bottom += 64.0f;

				paint.IsStroke = true;
				paint.Color = SKColors.Red;

				canvas.DrawRect (bounds, paint);
			}

			using (var paint = new SKPaint ()) {
				paint.TextSize = 64.0f;
				paint.IsAntialias = true;
				paint.Color = new SKColor (0x9C, 0xAF, 0xB7);
				paint.TextEncoding = SKTextEncoding.Utf16;

				canvas.DrawText ("Skia (UTF-16)", 0, 144.0f, paint);

				var bounds = new SKRect();
				paint.MeasureText ("Skia (UTF-16)", ref bounds);
				bounds.Top += 144.0f;
				bounds.Bottom += 144.0f;

				paint.IsStroke = true;
				paint.Color = SKColors.Red;

				canvas.DrawRect (bounds, paint);
			}

			using (var paint = new SKPaint ()) {
				paint.TextSize = 64.0f;
				paint.IsAntialias = true;
				paint.Color = new SKColor (0xE6, 0xB8, 0x9C);
				paint.TextEncoding = SKTextEncoding.Utf8;

				canvas.DrawText ("Skia (UTF-8)", 0, 224.0f, paint);

				var bounds = new SKRect();
				paint.MeasureText ("Skia (UTF-8)", ref bounds);
				bounds.Top += 224.0f;
				bounds.Bottom += 224.0f;

				paint.IsStroke = true;
				paint.Color = SKColors.Red;

				canvas.DrawRect (bounds, paint);
			}
		}
開發者ID:Core2D,項目名稱:SkiaSharp,代碼行數:61,代碼來源:SkiaSharp.Demos.cs

示例2: CreateLabelAsBitmap

        private static SKBitmap CreateLabelAsBitmap(LabelStyle style, string text, SKPaint paint)
        {
            var rect = new SKRect();
            paint.MeasureText(text, ref rect);

            var backRect = new SKRect(0, 0, rect.Width + 6, rect.Height + 6);

            var bitmap = new SKBitmap((int)backRect.Width, (int)backRect.Height);

            using (var target = new SKCanvas(bitmap))
            {
                target.Clear();

                DrawBackground(style, backRect, target);
                target.DrawText(text, -rect.Left + 3, -rect.Top +3, paint);
                return bitmap;
            }
        }
開發者ID:pauldendulk,項目名稱:Mapsui,代碼行數:18,代碼來源:LabelRenderer.cs


注:本文中的SkiaSharp.SKPaint.MeasureText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。