本文整理汇总了C#中Microsoft.Graphics.Canvas.CanvasDrawingSession.DrawText方法的典型用法代码示例。如果您正苦于以下问题:C# CanvasDrawingSession.DrawText方法的具体用法?C# CanvasDrawingSession.DrawText怎么用?C# CanvasDrawingSession.DrawText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Graphics.Canvas.CanvasDrawingSession
的用法示例。
在下文中一共展示了CanvasDrawingSession.DrawText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawCanvasState
private void DrawCanvasState(CanvasControl canvas, CanvasDrawingSession ds, int drawCount)
{
ds.Clear(Color.FromArgb(0, 0, 0, 0));
ds.DrawLine(0, 0, (float)canvas.ActualWidth, (float)canvas.ActualHeight, Colors.Aqua);
ds.DrawLine(0, (float)canvas.ActualHeight, (float)canvas.ActualWidth, 0, Colors.Aqua);
var text = String.Format("{0}x{1}\n{2} redraws", (int)canvas.ActualWidth, (int)canvas.ActualHeight, drawCount);
ds.DrawText(
text,
0, 0,
Colors.FloralWhite,
new CanvasTextFormat()
{
VerticalAlignment = CanvasVerticalAlignment.Top,
ParagraphAlignment = ParagraphAlignment.Left,
FontSize = 10
});
}
示例2: DrawElement
private void DrawElement(TextRender2MeasureMapElement element, CanvasDrawingSession session, Rect region)
{
var command = element.Command;
string text;
var textCnt = command.Content as ITextRenderTextContent;
if (textCnt != null)
{
text = textCnt.Text ?? "";
}
else
{
text = "";
}
using (var format = new CanvasTextFormat())
{
format.FontFamily = "Segoe UI";
format.FontSize = (float)Callback.PostFontSize;
format.WordWrapping = CanvasWordWrapping.NoWrap;
format.TrimmingGranularity = CanvasTextTrimmingGranularity.None;
format.HorizontalAlignment = CanvasHorizontalAlignment.Left;
session.DrawText(text, new Vector2((float)element.Placement.X, (float)element.Placement.Y), Colors.Black, format);
}
}
示例3: Draw
public void Draw(CanvasDrawingSession ds, float alpha = 1)
{
// Create a drop shadow by drawing a black circle with an offset position.
const float dropShadowOffset = 4;
ds.FillCircle(Position + new Vector2(dropShadowOffset), Radius, AdjustAlpha(Colors.Black, alpha));
// Draw a white X.
const float crossWidth = 3;
float crossSize = Radius * 0.8f;
Vector2 cross1 = new Vector2(crossSize, crossSize);
Vector2 cross2 = new Vector2(crossSize, -crossSize);
ds.DrawLine(Position - cross1, Position + cross1, AdjustAlpha(Colors.White, alpha), crossWidth);
ds.DrawLine(Position - cross2, Position + cross2, AdjustAlpha(Colors.White, alpha), crossWidth);
// Fill the circle with its unique color.
ds.FillCircle(Position, Radius, AdjustAlpha(color, alpha));
// White border around it.
ds.DrawCircle(Position, Radius, AdjustAlpha(Colors.White, alpha));
// Text label.
ds.DrawText(label, Position, AdjustAlpha(Colors.White, alpha), textFormat);
}
示例4: DrawForegroundText
private void DrawForegroundText(CanvasDrawingSession ds)
{
if (showTextLabels && !ThumbnailGenerator.IsDrawingThumbnail)
{
textFormat.VerticalAlignment = CanvasVerticalAlignment.Bottom;
textFormat.HorizontalAlignment = CanvasHorizontalAlignment.Right;
ds.DrawText("Dry Ink Foreground", new Vector2((float)canvasControl.Size.Width - 10, (float)canvasControl.Size.Height - 10), Colors.DarkGoldenrod, textFormat);
}
}
示例5: DrawNode
private void DrawNode(CanvasDrawingSession ds, Node node)
{
ds.FillCircle(node.Position, hitTestRadius, backgroundColor);
ds.DrawCircle(node.Position, hitTestRadius, foregroundColor, 4);
ds.DrawText(node.Name, node.Position, foregroundColor, textFormat);
}
示例6: DrawYAxisTexts
//draws the value texts
private void DrawYAxisTexts(CanvasDrawingSession ds, float height, RenderingOptions options)
{
// if needed do add CanvasTextFormat
ds.DrawText(options.MaxValueBuffered.ToString("#.#"), new Vector2(RIGHT_TEXT_MARGIN, 0), VALUESTEXT_COLOR);
var percent = (options.MaxValueBuffered - options.MinValueBuffered) * (1.0 / (DEFAULT_GRADIENTS));
for (int i = 1; i < DEFAULT_GRADIENTS; i++)
{
var percentVal = options.MaxValueBuffered - (percent * i);
// do add CanvasTextFormat
ds.DrawText(percentVal.ToString("#.#"), new Vector2(RIGHT_TEXT_MARGIN, (i * (height / DEFAULT_GRADIENTS))), VALUESTEXT_COLOR);
}
// do add CanvasTextFormat
ds.DrawText(options.MinValueBuffered.ToString("#.#"), new Vector2(RIGHT_TEXT_MARGIN, (height - BOTTOM_TEXT_MARGIN)), VALUESTEXT_COLOR);
}
示例7: Label
void Label(CanvasDrawingSession ds, float x, float y, string text)
{
var textFormat = new CanvasTextFormat()
{
FontSize = 16,
HorizontalAlignment = CanvasHorizontalAlignment.Center,
VerticalAlignment = CanvasVerticalAlignment.Bottom
};
ds.DrawText(text, x + 128, y + 256 - 16, Colors.White, textFormat);
}
示例8: Draw
public void Draw(CanvasDrawingSession ds, int frameCounter, float width, float height)
{
Size sz = sourceBitmap.Size;
double sourceSizeScale = (Math.Sin(frameCounter * 0.03) * 0.3) + 0.7;
Point center = new Point(Math.Sin(frameCounter * 0.02), (Math.Cos(frameCounter * 0.01)));
center.X *= (1 - sourceSizeScale) * sz.Width * 0.5;
center.Y *= (1 - sourceSizeScale) * sz.Height * 0.5;
center.X += sz.Width * 0.5;
center.Y += sz.Height * 0.5;
Rect sourceRect = new Rect(
center.X - sz.Width * sourceSizeScale * 0.5,
center.Y - sz.Height * sourceSizeScale * 0.5,
sz.Width * sourceSizeScale,
sz.Height * sourceSizeScale);
UpdateSourceRectRT(sourceRect);
var format = new CanvasTextFormat()
{
FontSize = 14,
HorizontalAlignment = CanvasHorizontalAlignment.Right,
VerticalAlignment = CanvasVerticalAlignment.Center,
WordWrapping = CanvasWordWrapping.Wrap
};
float y = 0;
float labelX = width / 2 - 5;
float imageX = width / 2 + 5;
float entryHeight = (float)sourceBitmap.Bounds.Height;
float margin = 14;
Rect labelRect = new Rect(0, y, labelX, entryHeight);
ds.DrawText(string.Format("Source image {0} DPI", sourceBitmap.Dpi), labelRect, Colors.White, format);
ds.FillRectangle(imageX, y, (float)sz.Width, (float)sz.Height, fillPattern);
ds.DrawImage(showSourceRectRT, imageX, y, showSourceRectRT.Bounds, 1, CanvasImageInterpolation.NearestNeighbor);
y += entryHeight + margin;
labelRect.Y = y;
ds.DrawText("D2D DrawBitmap (emulated dest rect)", labelRect, Colors.White, format);
ds.FillRectangle(imageX, y, (float)sz.Width, (float)sz.Height, fillPattern);
ds.DrawImage(sourceBitmap, imageX, y, sourceRect);
y += (float)sourceBitmap.Bounds.Height + 14;
labelRect.Y = y;
ds.DrawText("D2D DrawImage", labelRect, Colors.White, format);
ds.FillRectangle(imageX, y, (float)sz.Width, (float)sz.Height, fillPattern);
ds.DrawImage(sourceEffect, imageX, y, sourceRect);
}
示例9: DrawLabel
void DrawLabel(CanvasDrawingSession ds, string text, float h1InEmSpace, float h2InEmSpace, Side whichSide, int tab)
{
//
// The heights are offset from the baseline.
//
float h1 = baselineInWorldSpace + EmSpaceToWorldSpace(h1InEmSpace);
float h2 = baselineInWorldSpace + EmSpaceToWorldSpace(h2InEmSpace);
float midHeight = (h1 + h2) / 2;
float amountPerTab = sizeDim / 7.0f;
if (whichSide == Side.Left)
{
float margin = tab * amountPerTab;
ds.DrawLine(margin, h1, margin, h2, color, strokeWidth);
ds.DrawLine(margin, h1, horizontalMidpoint, h1, color, strokeWidth);
ds.DrawLine(margin, h2, horizontalMidpoint, h2, color, strokeWidth);
ds.DrawLine(margin - amountPerTab, midHeight, margin, midHeight, color, strokeWidth);
ds.DrawText(text, margin, midHeight, color, rightJustifiedTextFormat);
}
else
{
float rMargin = layoutSize.X - (tab * amountPerTab);
ds.DrawLine(rMargin, h1, rMargin, h2, color, strokeWidth);
ds.DrawLine(rMargin, h1, horizontalMidpoint, h1, color, strokeWidth);
ds.DrawLine(rMargin, h2, horizontalMidpoint, h2, color, strokeWidth);
ds.DrawLine(rMargin + amountPerTab, midHeight, rMargin, midHeight, color, strokeWidth);
ds.DrawText(text, rMargin, midHeight, color, leftJustifiedTextFormat);
}
NextLabel();
}
示例10: DrawNoBitmapErrorMessage
private void DrawNoBitmapErrorMessage(CanvasDrawingSession ds, int x, int y)
{
ds.DrawText(
"Please load bitmap before drawing it",
new Vector2(x, y),
Colors.Red,
new CanvasTextFormat()
{
FontSize = 24,
VerticalAlignment = CanvasVerticalAlignment.Center,
ParagraphAlignment = ParagraphAlignment.Center
});
}
示例11: DrawStuff
//.........这里部分代码省略.........
point, radiusX, radiusY,
NextRandomColor());
break;
case DrawnContentType.Ellipse_Thick:
NextRandomEllipse(horizontalLimit, verticalLimit, out point, out radiusX, out radiusY);
ds.DrawEllipse(
point, radiusX, radiusY,
NextRandomColor(),
thickStrokeWidth);
break;
case DrawnContentType.Ellipse_Fill:
NextRandomEllipse(horizontalLimit, verticalLimit, out point, out radiusX, out radiusY);
ds.FillEllipse(
point, radiusX, radiusY,
NextRandomColor());
break;
case DrawnContentType.Circle_Fill:
ds.FillCircle(
NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(),
100,
NextRandomColor());
break;
case DrawnContentType.Dashed_Lines:
DrawDashedLines(ds, NextRandomColor(), horizontalLimit, verticalLimit);
break;
case DrawnContentType.Text:
var p = NextRandomPoint(horizontalLimit, verticalLimit);
var x = (float)p.X;
var y = (float)p.Y;
var color = NextRandomColor();
ds.DrawLine(new Vector2(x, 0), new Vector2(x, verticalLimit), color);
ds.DrawLine(new Vector2(0, y), new Vector2(horizontalLimit, y), color);
ds.DrawText(
"Centered",
p.ToVector2(),
color,
new CanvasTextFormat()
{
FontSize = 18,
VerticalAlignment = CanvasVerticalAlignment.Center,
ParagraphAlignment = ParagraphAlignment.Center
});
var r = NextRandomRect(horizontalLimit, verticalLimit);
ds.DrawRectangle(r, color);
ds.DrawText(
m_quiteLongText,
r,
NextRandomColor(),
new CanvasTextFormat()
{
FontFamily = "Comic Sans MS",
FontSize = 18,
ParagraphAlignment = ParagraphAlignment.Justify,
Options = CanvasDrawTextOptions.Clip
});
break;
case DrawnContentType.ImageBrush:
if (m_bitmap_tiger != null)
{
m_imageBrush.Image = m_bitmap_tiger;
m_imageBrush.ExtendX = (CanvasEdgeBehavior)(m_random.Next(3));
m_imageBrush.ExtendY = (CanvasEdgeBehavior)(m_random.Next(3));
ds.FillRectangle(new Rect(0, 0, horizontalLimit, verticalLimit), m_imageBrush);
}
else
DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2);
break;
case DrawnContentType.Test_Scene0_Default:
GeometryTestScene0.DrawGeometryTestScene(ds, TestSceneRenderingType.Default);
break;
case DrawnContentType.Test_Scene0_Wireframe:
GeometryTestScene0.DrawGeometryTestScene(ds, TestSceneRenderingType.Wireframe);
break;
case DrawnContentType.Test_Scene1_Default:
GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Default);
break;
case DrawnContentType.Test_Scene1_Randomized:
GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Randomized);
break;
case DrawnContentType.Test_Scene1_Wireframe:
GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Wireframe);
break;
default:
System.Diagnostics.Debug.Assert(false); // Unexpected
break;
}
}
示例12: DrawDryInk_GeometryMethod
private void DrawDryInk_GeometryMethod(CanvasDrawingSession ds, IReadOnlyList<InkStroke> strokes)
{
//
// This converts the ink strokes to geometry, then draws the geometry outline
// with a dotted stroke style.
//
var strokeStyle = new CanvasStrokeStyle { DashStyle = CanvasDashStyle.Dot };
var strokesGroupedByColor = from stroke in strokes
where !IsPencilStroke(stroke)
group stroke by stroke.DrawingAttributes.Color into strokesOfColor
select strokesOfColor;
foreach (var strokesOfColor in strokesGroupedByColor)
{
var geometry = CanvasGeometry.CreateInk(ds, strokesOfColor.ToList()).Outline();
ds.DrawGeometry(geometry, strokesOfColor.Key, 1, strokeStyle);
}
// Display text labels in place of any pencil strokes, because we cannot create geometry for those.
foreach (var pencilStroke in strokes.Where(IsPencilStroke))
{
ds.DrawText("CanvasGeometry.CreateInk does not support pencil strokes",
pencilStroke.BoundingRect,
pencilStroke.DrawingAttributes.Color,
centerTextFormat);
}
}
示例13: Draw
public void Draw(CanvasDrawingSession ds, Matrix3x2 transform)
{
var pos = Vector2.Transform(Pos, transform);
var mu = (float)Math.Sin(DeadMu * Math.PI * 0.5);
var scale = Matrix3x2.CreateScale(1.0f + mu * 10.0f);
var center = new Vector2(pos.X, pos.Y);
ds.Transform = Matrix3x2.CreateTranslation(-center) * scale * Matrix3x2.CreateTranslation(center);
Color c = Color.FromArgb((byte)((1.0f - mu) * 255.0f), 255, 255, 255);
ds.DrawText(Value.ToString(), pos, c, TextFormat);
}
示例14: DrawBackground
private void DrawBackground(CanvasDrawingSession ds, Matrix3x2 transform)
{
const int levelUpTime = 60;
// After levelling up we flash the screen white for a bit
Color normalColor = Colors.Blue;
Color levelUpFlashColor = Colors.White;
var flashAmount = Math.Min(1, (leveledUpTimer / (float)levelUpTime));
ds.Clear(InterpolateColors(normalColor, levelUpFlashColor, flashAmount));
var topLeft = Vector2.Transform(new Vector2(0, 0), transform);
var bottomRight = Vector2.Transform(new Vector2(1, 1), transform);
var middle = (bottomRight.X - topLeft.X) / 2 + topLeft.X;
// and display some text to let the player know what happened
if (leveledUpTimer < levelUpTime * 2)
{
ds.DrawText("Level Up!", middle, 0, Colors.White, levelUpFormat);
}
// Draw some lines to show where the top / bottom of the play area is.
var topLine = topLeft.Y - Letter.TextFormat.FontSize;
var bottomLine = bottomRight.Y + Letter.TextFormat.FontSize;
Color lineColor = levelUpFlashColor;
lineColor.A = 128;
ds.DrawLine(0, topLine, bottomRight.X, topLine, lineColor, 3);
ds.DrawLine(0, bottomLine, bottomRight.X, bottomLine, lineColor, 3);
}
示例15: Draw
public void Draw(CanvasAnimatedDrawEventArgs args, CanvasDrawingSession ds, float width, float height)
{
drawCount++;
const int maxEntries = 120;
updatesPerDraw.Enqueue(updatesThisDraw);
while (updatesPerDraw.Count > maxEntries)
updatesPerDraw.Dequeue();
ds.Antialiasing = CanvasAntialiasing.Aliased;
var barWidth = width / (float)maxEntries;
const float heightPerUpdate = 10.0f;
float barBottom = height * 0.25f;
int maxUpdates = 0;
int maxIndex = -1;
int index = 0;
foreach (int update in updatesPerDraw)
{
float barHeight = update * heightPerUpdate;
Color color = Colors.Gray;
if ((Math.Max(0, drawCount - maxEntries) + index) % 60 == 0)
color = Colors.White;
ds.FillRectangle(barWidth * index, height - barHeight - barBottom, barWidth, barHeight + barBottom, color);
if (update > maxUpdates)
{
maxIndex = index;
maxUpdates = update;
}
index++;
}
if (maxUpdates > 0)
{
var y = height - maxUpdates * heightPerUpdate - barBottom;
ds.DrawLine(0, y, width, y, Colors.White, 1, maxStroke);
ds.DrawText(
maxUpdates.ToString(),
0,
height - maxUpdates * heightPerUpdate - barBottom,
Colors.White,
new CanvasTextFormat()
{
FontSize = heightPerUpdate * 2,
HorizontalAlignment = CanvasHorizontalAlignment.Left,
VerticalAlignment = CanvasVerticalAlignment.Bottom
});
}
using (var textFormat = new CanvasTextFormat()
{
FontSize = width * 0.05f,
HorizontalAlignment = CanvasHorizontalAlignment.Left,
VerticalAlignment = CanvasVerticalAlignment.Top
})
{
float y = 1;
ds.DrawText("Updates per Draw", 1, y, Colors.White, textFormat);
y += textFormat.FontSize * 2;
textFormat.FontSize *= 0.6f;
ds.DrawText(string.Format("{0} total updates", args.Timing.UpdateCount), 1, y, Colors.Red, textFormat);
y += textFormat.FontSize * 1.2f;
ds.DrawText(string.Format("{0} total draws", drawCount), 1, y, Colors.Green, textFormat);
}
updatesThisDraw = 0;
}