This documentation is archived and is not being maintained.

DrawingVisual Class

DrawingVisual is a visual object that can be used to render vector graphics on the screen. The content is persisted by the system.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)

public class DrawingVisual : ContainerVisual
<DrawingVisual .../>

DrawingVisual is a lightweight drawing class that is used to render shapes, images, or text. This class is considered lightweight because it does not provide layout, input, focus, or event handling, which improves its performance. For this reason, drawings are ideal for backgrounds and clip art.

In order to use DrawingVisual objects, you need to create a host container for the objects. The host container object must be derived from the FrameworkElement class, which provides the layout and event handling support that the DrawingVisual class does not support. The host container object does not display any visual properties, since its main purpose is to contain child objects. For more information, see Using DrawingVisual Objects.

For a complete example showing how to create DrawingVisual objects with a host container, see the Hit Test Using DrawingVisuals Sample.

This example shows how you can create a bitmap from a Visual. A DrawingVisual is rendered with FormattedText. The Visual is then rendered to the RenderTargetBitmap creating a bitmap of the given text.

Image myImage = new Image();
FormattedText text = new FormattedText("ABC",
        new CultureInfo("en-us"),
        new Typeface(this.FontFamily, FontStyles.Normal, FontWeights.Normal, new FontStretch()),

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

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0