I have a VisualBrush and need this VisualBrush as a Drawing. Anyone knows how this can be done? Thanks for any hint!
Asked
Active
Viewed 2,014 times
2 Answers
5
Here's the XAML version:
<GeometryDrawing Geometry="M0,0 L1,0 1,1 0,1 Z">
<GeometryDrawing.Brush>
<VisualBrush>
...
</VisualBrush>
</GeometryDrawing.Brush>
</GeometryDrawing>

Ray Burns
- 62,163
- 12
- 140
- 141
2
Your question doesn't really make sense, because a VisualBrush
is unrelated to a Drawing
(it would make more sense with a DrawingBrush
). However, you can create a Drawing
by using the VisualBrush
to paint on it. Something like that should work :
public static Drawing GetDrawing(TileBrush brush)
{
DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
drawingContext.DrawRectangle(brush, new Pen(Brushes.Transparent, 0.0), brush.ViewPort);
drawingContext.Close();
return drawingVisual.Drawing;
}
(this is valid for any brush inherited from TileBrush
, not just a VisualBrush
)

Thomas Levesque
- 286,951
- 70
- 623
- 758
-
Thanks for your reply, looks very promising :-) Note that you can just set the pen to null drawingContext.DrawRectangle(brush, null, 0.0), brush.ViewPort); – stefan.at.kotlin Jun 01 '10 at 18:44