次の方法で共有


方法 : ビジュアルの描画コンテンツを列挙する

Drawing オブジェクトは、Visual のコンテンツを列挙するためのオブジェクト モデルを提供します。

使用例

GetDrawing メソッドを使用して VisualDrawingGroup 値を取得し、列挙する例を次に示します。

メモメモ

ビジュアルのコンテンツを列挙すると、ベクター グラフィックス命令リストとして基になるレンダリング データ表現が取得されるのではなく、Drawing オブジェクトが取得されます。詳細については、「WPF グラフィックス レンダリングの概要」を参照してください。

public void RetrieveDrawing(Visual v)
{
    DrawingGroup dGroup = VisualTreeHelper.GetDrawing(v);
    EnumDrawingGroup(dGroup);

}

 // Enumerate the drawings in the DrawingGroup.
 public void EnumDrawingGroup(DrawingGroup drawingGroup)
 {
     DrawingCollection dc = drawingGroup.Children;

     // Enumerate the drawings in the DrawingCollection.
     foreach (Drawing drawing in dc)
     {
         // If the drawing is a DrawingGroup, call the function recursively.
         if (drawing.GetType() == typeof(DrawingGroup))
         {
             EnumDrawingGroup((DrawingGroup)drawing);
         }
         else if (drawing.GetType() == typeof(GeometryDrawing))
         {
             // Perform action based on drawing type.  
         }
         else if (drawing.GetType() == typeof(ImageDrawing))
         {
             // Perform action based on drawing type.
         }
         else if (drawing.GetType() == typeof(GlyphRunDrawing))
         {
             // Perform action based on drawing type.
         }
         else if (drawing.GetType() == typeof(VideoDrawing))
         {
             // Perform action based on drawing type.
         }
     }
 }

参照

参照

Drawing

DrawingGroup

VisualTreeHelper

概念

Drawing オブジェクトの概要

WPF グラフィックス レンダリングの概要