【WPF】建立文字字串的路徑PathGeometry
阿新 • • 發佈:2018-11-09
/// <summary> /// 建立文字路徑 /// </summary> /// <param name="word">文字字串</param> /// <param name="point">顯示位置</param> /// <param name="typeface">字型資訊</param> /// <param name="fontSize">字型大小</param> /// <returns></returns>public static Geometry CreateTextPath(string word, Point point, Typeface typeface, int fontSize) { FormattedText text = new FormattedText(word, new System.Globalization.CultureInfo("zh-cn"), FlowDirection.LeftToRight, typeface, fontSize, Brushes.Black); Geometry geo= text.BuildGeometry(point); PathGeometry path = geo.GetFlattenedPathGeometry(); return path; }
使用:
var pathgeometry = CreateTextPath("萌妻D小曼", new Point(0, 0), new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal), (int)fontsize);