0

我想通过 GeometryDrawing 绘制字母 A~Z。

4

1 回答 1

3

这是一个如何使用GeometryDrawing.

XAML 文件 Window1.xaml:

<Window x:Class="TextDrawing.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="150" Width="300">
    <Canvas>
        <Image Stretch="None" HorizontalAlignment="Left" Margin="10">
            <Image.Source>
                <DrawingImage>
                    <DrawingImage.Drawing>
                        <GeometryDrawing x:Name="geoDrawing"/>
                    </DrawingImage.Drawing>
                </DrawingImage>
            </Image.Source>
        </Image>
    </Canvas>
</Window>

C# 文件 Window1.xaml.cs:

using System.Windows;
using System.Windows.Media;
using System.Globalization;

namespace TextDrawing
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            FormattedText atoz = new FormattedText("ABC...XYZ",
                CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                new Typeface("Arial"), 50.0, Brushes.Black);
            Geometry geo = atoz.BuildGeometry(new Point(0, 0));
            geoDrawing.Geometry = geo;
            geoDrawing.Pen = new Pen(Brushes.Black, 1.0);
            geoDrawing.Brush = Brushes.Yellow;
        }
    }
}

结果输出:

使用 GeometryDrawing 渲染的文本

于 2011-06-26T06:42:34.037 回答