C#代码:
public void RetrieveDrawing(Visual v)
{
DrawingGroup dGroup = VisualTreeHelper.GetDrawing(v);
EnumDrawingGroup(dGroup);
}
public void EnumDrawingGroup(DrawingGroup drawingGroup)
{
DrawingCollection dc = drawingGroup.Children;
foreach (Drawing drawing in dc)
{
// 如果是DrawingGroup,递归枚举
if (drawing.GetType() == typeof(DrawingGroup))
{
EnumDrawingGroup((DrawingGroup)drawing);
}
else if (drawing.GetType() == typeof(GeometryDrawing))
{
// 处理代理
}
else if (drawing.GetType() == typeof(ImageDrawing))
{
// 处理代理
}
else if (drawing.GetType() == typeof(GlyphRunDrawing))
{
// 处理代理
}
else if (drawing.GetType() == typeof(VideoDrawing))
{
// 处理代理
}
}
}
由于代码很简单,不赘述.