2

我正在尝试使用不同的 API 集(WinForms、WPF 和 Windows Phone 8)以编程方式使用 C# 绘制扭曲的文本字符串。

使用 WinForms,我设法通过 GDI+ 的System.Drawing.Drawing2D.GraphicsPath类以这种方式实现了这一点:

System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddString(text, font.FontFamily, (int)font.Style, font.Size, new Drawing::Point(0, 0), Drawing::StringFormat.GenericDefault);
PointF[] origPoints = path.PathPoints;
PointF[] newPoints = new PointF[originalPath.PointCount];
/* Generate the values of newPoints items from origPoints items */
System.Drawing.Drawing2D.GraphicsPath distortion = new System.Drawing.Drawing2D.GraphicsPath(newPoints, path.PathTypes);

/* ...Create Graphics object... */

graphics.FillPath(Drawing::Brushes.Black, distortion);

使用 WPF,我设法通过System.Windows.Media.Geometry从 a创建 a,通过 aSystem.Windows.Media.FormattedText将其转换为a ,然后手动创建其属性的解冻深层副本并修改每个. 它看起来像这样:PathGeometrySystem.Windows.Shapes.PathFiguresPointPolyLineSegmentPathFigurePathGeometry

FormattedText formattedText = new Media::FormattedText(text, 
            System.Globalization.CultureInfo.GetCultureInfo("en-us"),
            Windows::FlowDirection.LeftToRight,
            typeface, fontSize, Media::Brushes.Transparent);
Geometry geom = formattedText.BuildGeometry(new Point(0, 0));

Path path = new Path();
path.Data = geom;
PathGeometry pathGeom = path.Data.GetFlattenedPathGeometry();
PathGeometry newGeom = new PathGeometry(); /* Cloned geometry. We can't modify the original - it's frozen */

newGeom.Figures = pathGeom.Figures.Clone();
/* Etc... Clone the Segments for each Figure, then the Points for every Segment */

/* ...Create DrawingContext... */

context.DrawGeometry(Media::Brushes.Black, null, newGeom);

我尝试将后一种解决方案移植到 Windows Phone(Windows Phone 8),但我发现它缺少FormattedText,以及s、DrawingContexts和s集合的方法(另外,它缺少and并且我没有丝毫的想法关于我将如何以及在哪里渲染修改后的,但这可以看作是一个单独的问题)。Geometry.GetFlattenedPathGeometry()CloneFigureSegmentPointRenderTargetBitmapDrawingVisualGeometry

如何将我的 WPF 代码移植到 Windows Phone 8?我可以使用哪些替代方法Geometry从文本字符串构建 a,PathGeometry从 my获取 a Geometry,以及如何获取Clone其内容?

或者是否有更好的选择可以在 Windows Phone 8 上以编程方式扭曲文本?

4

0 回答 0