我正在尝试使用不同的 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 ,然后手动创建其属性的解冻深层副本并修改每个. 它看起来像这样:PathGeometry
System.Windows.Shapes.Path
Figures
Point
PolyLineSegment
PathFigure
PathGeometry
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、DrawingContext
s和s集合的方法(另外,它缺少and并且我没有丝毫的想法关于我将如何以及在哪里渲染修改后的,但这可以看作是一个单独的问题)。Geometry.GetFlattenedPathGeometry()
Clone
Figure
Segment
Point
RenderTargetBitmap
DrawingVisual
Geometry
如何将我的 WPF 代码移植到 Windows Phone 8?我可以使用哪些替代方法Geometry
从文本字符串构建 a,PathGeometry
从 my获取 a Geometry
,以及如何获取Clone
其内容?
或者是否有更好的选择可以在 Windows Phone 8 上以编程方式扭曲文本?