共用方式為


HOW TO:從 Visual 建立點陣圖

更新:2007 年 11 月

本範例顯示如何從 Visual 建立點陣圖。DrawingVisual 會使用 FormattedText 呈現。Visual 接著再呈現在 RenderTargetBitmap,建立所指定文字的點陣圖。

範例

Dim myImage As New Image()
Dim [text] As New FormattedText("ABC", New CultureInfo("en-us"), System.Windows.FlowDirection.LeftToRight, New Typeface(Me.FontFamily, FontStyles.Normal, FontWeights.Normal, New FontStretch()), Me.FontSize, Me.Foreground)

Dim drawingVisual As New DrawingVisual()
Dim drawingContext As DrawingContext = drawingVisual.RenderOpen()
drawingContext.DrawText([text], New System.Windows.Point(2, 2))
drawingContext.Close()

Dim bmp As New RenderTargetBitmap(180, 180, 120, 96, PixelFormats.Pbgra32)
bmp.Render(drawingVisual)
myImage.Source = bmp
Image myImage = new Image();
FormattedText text = new FormattedText("ABC",
        new CultureInfo("en-us"),
        FlowDirection.LeftToRight,
        new Typeface(this.FontFamily, FontStyles.Normal, FontWeights.Normal, new FontStretch()),
        this.FontSize,
        this.Foreground);

DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
drawingContext.DrawText(text, new Point(2, 2));
drawingContext.Close();

RenderTargetBitmap bmp = new RenderTargetBitmap(180, 180, 120, 96, PixelFormats.Pbgra32);
bmp.Render(drawingVisual);
myImage.Source = bmp;

請參閱

概念

影像處理概觀

繪圖物件概觀

使用 DrawingVisual 物件

參考

DrawingContext