我只需要画几个数字。仅仅定义GlyphRun和FontRenderingEmSize就足够了吗?如果没有,请建议我如何绘制字符串"123“(如何定义GlyphRun对象)。我写了这段代码:
var gr = new GlyphRun();
gr.Characters = new List<char>() { '1', '2' }; //Mistake
gr.FontRenderingEmSize = 20;
var Glyph = new GlyphRunDrawing(Brushes.Black, gr);发布于 2022-07-25 07:20:32
我找到了我的一个老帮手班。也许你可以利用它。
public static class GlyphRunText
{
public static GlyphRun Create(
string text, Typeface typeface, double emSize, Point baselineOrigin)
{
GlyphTypeface glyphTypeface;
if (!typeface.TryGetGlyphTypeface(out glyphTypeface))
{
throw new ArgumentException(string.Format(
"{0}: no GlyphTypeface found", typeface.FontFamily));
}
var glyphIndices = new ushort[text.Length];
var advanceWidths = new double[text.Length];
for (int i = 0; i < text.Length; i++)
{
var glyphIndex = glyphTypeface.CharacterToGlyphMap[text[i]];
glyphIndices[i] = glyphIndex;
advanceWidths[i] = glyphTypeface.AdvanceWidths[glyphIndex] * emSize;
}
return new GlyphRun(
glyphTypeface, 0, false, emSize,
glyphIndices, baselineOrigin, advanceWidths,
null, null, null, null, null, null);
}
}https://stackoverflow.com/questions/73101580
复制相似问题