我正在尝试使用不同的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
创建System.Windows.Media.FormattedText
,通过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
,DrawingContext
,Geometry.GetFlattenedPathGeometry()
和{{1 Clone
,Figure
和Segment
s集合的方法(也是Point
和RenderTargetBitmap
和DrawingVisual
错过的方法我对如何以及在何处呈现修改后的Geometry
一无所知,但这可以被视为一个单独的问题。)
如何将WPF代码移植到Windows Phone 8?我可以使用哪些替代方法从文本字符串构建Geometry
,从PathGeometry
获取Geometry
,以及如何Clone
其内容?
或者是否有更好的方法可以在Windows Phone 8上以编程方式扭曲文本?