Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DrawingContext Class

Describes visual content using draw, push, and pop commands.

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

[<AbstractClass>]
type DrawingContext =  
    class 
        inherit DispatcherObject 
        interface IDisposable 
    end

The DrawingContext type exposes the following members.

  NameDescription
Public propertyDispatcherGets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.)
Top

  NameDescription
Public methodCheckAccessDetermines whether the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Public methodCloseCloses the DrawingContext and flushes the content. Afterward, the DrawingContext cannot be modified.
Protected methodDisposeCoreReleases all resources used by the DrawingContext.
Public methodDrawDrawingDraws the specified Drawing object.
Public methodDrawEllipse(Brush, Pen, Point, Double, Double)Draws an ellipse with the specified Brush and Pen.
Public methodDrawEllipse(Brush, Pen, Point, AnimationClock, Double, AnimationClock, Double, AnimationClock)Draws an ellipse with the specified Brush and Pen and applies the specified animation clocks.
Public methodDrawGeometryDraws the specified Geometry using the specified Brush and Pen.
Public methodDrawGlyphRunDraws the specified text.
Public methodDrawImage(ImageSource, Rect)Draws an image into the region defined by the specified Rect.
Public methodDrawImage(ImageSource, Rect, AnimationClock)Draws an image into the region defined by the specified Rect and applies the specified animation clock.
Public methodDrawLine(Pen, Point, Point)Draws a line between the specified points using the specified Pen.
Public methodDrawLine(Pen, Point, AnimationClock, Point, AnimationClock)Draws a line between the specified points using the specified Pen and applies the specified animation clocks.
Public methodDrawRectangle(Brush, Pen, Rect)Draws a rectangle with the specified Brush and Pen. The pen and the brush can be a null reference (Nothing in Visual Basic).
Public methodDrawRectangle(Brush, Pen, Rect, AnimationClock)Draws a rectangle with the specified Brush and Pen and applies the specified animation clocks.
Public methodDrawRoundedRectangle(Brush, Pen, Rect, Double, Double)Draws a rounded rectangle with the specified Brush and Pen.
Public methodDrawRoundedRectangle(Brush, Pen, Rect, AnimationClock, Double, AnimationClock, Double, AnimationClock)Draws a rounded rectangle with the specified Brush and Pen and applies the specified animation clocks.
Public methodDrawTextDraws formatted text at the specified location.
Public methodDrawVideo(MediaPlayer, Rect)Draws a video into the specified region.
Public methodDrawVideo(MediaPlayer, Rect, AnimationClock)Draws a video into the specified region and applies the specified animation clock.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodPopPops the last opacity mask, opacity, clip, effect, or transform operation that was pushed onto the drawing context.
Public methodPushClipPushes the specified clip region onto the drawing context.
Public methodPushEffect Obsolete. Pushes the specified BitmapEffect onto the drawing context.
Public methodPushGuidelineSetPushes the specified GuidelineSet onto the drawing context.
Public methodPushOpacity(Double)Pushes the specified opacity setting onto the drawing context.
Public methodPushOpacity(Double, AnimationClock)Pushes the specified opacity setting onto the drawing context and applies the specified animation clock.
Public methodPushOpacityMaskPushes the specified opacity mask onto the drawing context.
Public methodPushTransformPushes the specified Transform onto the drawing context.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodVerifyAccessEnforces that the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Protected methodVerifyApiNonstructuralChangeThis member supports the WPF infrastructure and is not intended to be used directly from your code. 
Top

  NameDescription
Explicit interface implemetationPrivate methodIDisposable.DisposeThis member supports the Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.
Top

Use a DrawingContext to populate a Visual or a Drawing with visual content.

Although the DrawingContext draw methods appear similar to the draw methods of the System.Drawing.Graphics type, they function very differently: DrawingContext is used with a retained mode graphics system, while the System.Drawing.Graphics type is used with an immediate mode graphics system. When you use a DrawingContext object's draw commands, you are actually storing a set of rendering instructions (although the exact storage mechanism depends on the type of object that supplies the DrawingContext) that will later be used by the graphics system; you are not drawing to the screen in real-time. For more information about how the Windows Presentation Foundation (WPF) graphics system works, see WPF Graphics Rendering Overview.

You never directly instantiate a DrawingContext; you can, however, acquire a drawing context from certain methods, such as DrawingGroup.Open and DrawingVisual.RenderOpen.

The following example retrieves a DrawingContext from a DrawingVisual and uses it to draw a rectangle.

No code example is currently available or this language may not be supported.

The next example demonstrates the PushOpacity, PushEffect, and Pop commands. The DrawingContext is obtained from a DrawingGroup and displayed using an Image control.

No code example is currently available or this language may not be supported.

More Code

How to: Draw Text to a VisualThe following example shows how to draw text to a DrawingVisual using a DrawingContext object. A drawing context is returned by calling the RenderOpen method of a DrawingVisual object. You can draw graphics and text into a drawing context.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

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