2011-06-26 25 views
0

ジオメトリドローイングでA〜Zという単語を描きたいのですが...GeometryDrawingの使い方は?

誰にでも教えていただけますか?ここで

おかげで...

+1

は、私はそれがあるとは思いません実際にあなたがしたいこと。ジオメトリ図面にテキストを描画するには、まずテキストをパスデータに変換する必要があります。あなたは何をしようとしているのより広い記述を提供できますか?あなたが試みていることを推測しなければならない場合は、キャンバス上のテキストブロックがより適切かもしれません。 – JacobJ

答えて

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; 
     } 
    } 
} 

結果の出力:

Text rendered with GeometryDrawing