【WPF】創建文本字符串的路徑PathGeometry


        /// <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);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM