DrawingContext DrawingContext DrawingContext DrawingContext Class

Definición

Describe contenido visual que utiliza comandos de dibujo, inserción y extracción.Describes visual content using draw, push, and pop commands.

public ref class DrawingContext abstract : System::Windows::Threading::DispatcherObject, IDisposable
public abstract class DrawingContext : System.Windows.Threading.DispatcherObject, IDisposable
type DrawingContext = class
    inherit DispatcherObject
    interface IDisposable
Public MustInherit Class DrawingContext
Inherits DispatcherObject
Implements IDisposable
Herencia
Implementaciones

Ejemplos

En el ejemplo siguiente se recupera DrawingContext un de DrawingVisual un y se utiliza para dibujar un rectángulo.The following example retrieves a DrawingContext from a DrawingVisual and uses it to draw a rectangle.

// Create a DrawingVisual that contains a rectangle.
private DrawingVisual CreateDrawingVisualRectangle()
{
    DrawingVisual drawingVisual = new DrawingVisual();

    // Retrieve the DrawingContext in order to create new drawing content.
    DrawingContext drawingContext = drawingVisual.RenderOpen();

    // Create a rectangle and draw it in the DrawingContext.
    Rect rect = new Rect(new System.Windows.Point(160, 100), new System.Windows.Size(320, 80));
    drawingContext.DrawRectangle(System.Windows.Media.Brushes.LightBlue, (System.Windows.Media.Pen)null, rect);

    // Persist the drawing content.
    drawingContext.Close();

    return drawingVisual;
}
' Create a DrawingVisual that contains a rectangle.
Private Function CreateDrawingVisualRectangle() As DrawingVisual
	Dim drawingVisual As New DrawingVisual()

	' Retrieve the DrawingContext in order to create new drawing content.
	Dim drawingContext As DrawingContext = drawingVisual.RenderOpen()

	' Create a rectangle and draw it in the DrawingContext.
	Dim rect As New Rect(New Point(160, 100), New Size(320, 80))
	drawingContext.DrawRectangle(Brushes.LightBlue, CType(Nothing, Pen), rect)

	' Persist the drawing content.
	drawingContext.Close()

	Return drawingVisual
End Function

En el ejemplo siguiente se PushOpacitymuestran PushEffectlos comandos Pop , y.The next example demonstrates the PushOpacity, PushEffect, and Pop commands. Se obtiene de y se muestra mediante un Image control. DrawingGroup DrawingContextThe DrawingContext is obtained from a DrawingGroup and displayed using an Image control.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Media.Effects;

namespace SDKSample
{


    public class PushEffectExample : Page
    {

        public PushEffectExample()
        {
            Pen shapeOutlinePen = new Pen(Brushes.Black, 2);
            shapeOutlinePen.Freeze();

            // Create a DrawingGroup
            DrawingGroup dGroup = new DrawingGroup();

            // Obtain a DrawingContext from 
            // the DrawingGroup.
            using (DrawingContext dc = dGroup.Open())
            {
                // Draw a rectangle at full opacity.
                dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, new Rect(0, 0, 25, 25));

                // Push an opacity change of 0.5. 
                // The opacity of each subsequent drawing will
                // will be multiplied by 0.5.
                dc.PushOpacity(0.5);

                // This rectangle is drawn at 50% opacity.
                dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, new Rect(25, 25, 25, 25));

                // Blurs subsquent drawings. 
                dc.PushEffect(new BlurBitmapEffect(), null);

                // This rectangle is blurred and drawn at 50% opacity (0.5 x 0.5). 
                dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, new Rect(50, 50, 25, 25));

                // This rectangle is also blurred and drawn at 50% opacity.
                dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, new Rect(75, 75, 25, 25));

                // Stop applying the blur to subsquent drawings.
                dc.Pop();

                // This rectangle is drawn at 50% opacity with no blur effect.
                dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, new Rect(100, 100, 25, 25));
            }

            // Display the drawing using an image control.
            Image theImage = new Image();
            DrawingImage dImageSource = new DrawingImage(dGroup);
            theImage.Source = dImageSource;

            this.Content = theImage;

        }




    }

}
Imports System.Windows.Media.Animation
Imports System.Windows.Media.Effects

Namespace SDKSample


	Public Class PushEffectExample
		Inherits Page

		Public Sub New()
			Dim shapeOutlinePen As New Pen(Brushes.Black, 2)
			shapeOutlinePen.Freeze()

			' Create a DrawingGroup
			Dim dGroup As New DrawingGroup()

			' Obtain a DrawingContext from 
			' the DrawingGroup.
			Using dc As DrawingContext = dGroup.Open()
				' Draw a rectangle at full opacity.
				dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, New Rect(0, 0, 25, 25))

				' Push an opacity change of 0.5. 
				' The opacity of each subsequent drawing will
				' will be multiplied by 0.5.
				dc.PushOpacity(0.5)

				' This rectangle is drawn at 50% opacity.
				dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, New Rect(25, 25, 25, 25))

				' Blurs subsquent drawings. 
                dc.PushEffect(New BlurBitmapEffect(), Nothing)

				' This rectangle is blurred and drawn at 50% opacity (0.5 x 0.5). 
				dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, New Rect(50, 50, 25, 25))

				' This rectangle is also blurred and drawn at 50% opacity.
				dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, New Rect(75, 75, 25, 25))

				' Stop applying the blur to subsquent drawings.
				dc.Pop()

				' This rectangle is drawn at 50% opacity with no blur effect.
				dc.DrawRectangle(Brushes.Blue, shapeOutlinePen, New Rect(100, 100, 25, 25))
			End Using

			' Display the drawing using an image control.
			Dim theImage As New Image()
			Dim dImageSource As New DrawingImage(dGroup)
			theImage.Source = dImageSource

			Me.Content = theImage

		End Sub




	End Class

End Namespace

Comentarios

Use un DrawingContext para rellenar un Drawing Visual o un con contenido visual.Use a DrawingContext to populate a Visual or a Drawing with visual content.

Aunque los DrawingContext System.Drawing.Graphics métodos de dibujo parecen similares a los métodos de dibujo del tipo, funcionan de forma muy DrawingContext diferente: se usa con un sistema de gráficos de modo System.Drawing.Graphics retenido, mientras que el tipo se usa con un modo inmediato sistema de gráficos.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. Cuando se usan comandos DrawingContext de dibujo de un objeto, en realidad se almacena un conjunto de instrucciones de representación (aunque el mecanismo de almacenamiento exacto depende del tipo de objeto que proporciona DrawingContextel) que el sistema de gráficos usará más adelante. no se dibujan en la pantalla en tiempo real.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. Para obtener más información sobre cómo funciona el sistema de gráficos de Windows Presentation Foundation (WPF), vea información general sobre la representación de gráficos en WPF.For more information about how the Windows Presentation Foundation (WPF) graphics system works, see WPF Graphics Rendering Overview.

Nunca se crean instancias directamente de DrawingContextun; sin embargo, se puede adquirir un contexto de dibujo de determinados métodos, DrawingGroup.Open como DrawingVisual.RenderOpeny.You never directly instantiate a DrawingContext; you can, however, acquire a drawing context from certain methods, such as DrawingGroup.Open and DrawingVisual.RenderOpen.

Métodos

CheckAccess() CheckAccess() CheckAccess() CheckAccess()

Determina si el subproceso de la llamada tiene acceso a DispatcherObject.Determines whether the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)
Close() Close() Close() Close()

Cierra el objeto DrawingContext y vacía el contenido.Closes the DrawingContext and flushes the content. Después, no se puede modificar DrawingContext.Afterward, the DrawingContext cannot be modified.

DisposeCore() DisposeCore() DisposeCore() DisposeCore()

Libera todos los recursos que usa DrawingContext.Releases all resources used by the DrawingContext.

DrawDrawing(Drawing) DrawDrawing(Drawing) DrawDrawing(Drawing) DrawDrawing(Drawing)

Dibuja el objeto Drawing especificado.Draws the specified Drawing object.

DrawEllipse(Brush, Pen, Point, AnimationClock, Double, AnimationClock, Double, AnimationClock) DrawEllipse(Brush, Pen, Point, AnimationClock, Double, AnimationClock, Double, AnimationClock) DrawEllipse(Brush, Pen, Point, AnimationClock, Double, AnimationClock, Double, AnimationClock) DrawEllipse(Brush, Pen, Point, AnimationClock, Double, AnimationClock, Double, AnimationClock)

Dibuja una elipse con los objetos Brush y Pen especificados y aplica los relojes de animación especificados.Draws an ellipse with the specified Brush and Pen and applies the specified animation clocks.

DrawEllipse(Brush, Pen, Point, Double, Double) DrawEllipse(Brush, Pen, Point, Double, Double) DrawEllipse(Brush, Pen, Point, Double, Double) DrawEllipse(Brush, Pen, Point, Double, Double)

Dibuja una elipse con los objetos Brush y Pen especificados.Draws an ellipse with the specified Brush and Pen.

DrawGeometry(Brush, Pen, Geometry) DrawGeometry(Brush, Pen, Geometry) DrawGeometry(Brush, Pen, Geometry) DrawGeometry(Brush, Pen, Geometry)

Dibuja el objeto Geometry especificado mediante los objetos Brush y Pen especificados.Draws the specified Geometry using the specified Brush and Pen.

DrawGlyphRun(Brush, GlyphRun) DrawGlyphRun(Brush, GlyphRun) DrawGlyphRun(Brush, GlyphRun) DrawGlyphRun(Brush, GlyphRun)

Dibuja el texto especificado.Draws the specified text.

DrawImage(ImageSource, Rect) DrawImage(ImageSource, Rect) DrawImage(ImageSource, Rect) DrawImage(ImageSource, Rect)

Dibuja una imagen en la región definida por la estructura Rect especificada.Draws an image into the region defined by the specified Rect.

DrawImage(ImageSource, Rect, AnimationClock) DrawImage(ImageSource, Rect, AnimationClock) DrawImage(ImageSource, Rect, AnimationClock) DrawImage(ImageSource, Rect, AnimationClock)

Dibuja una imagen en la región definida por la estructura Rect especificada y aplica el reloj de animación especificado.Draws an image into the region defined by the specified Rect and applies the specified animation clock.

DrawLine(Pen, Point, AnimationClock, Point, AnimationClock) DrawLine(Pen, Point, AnimationClock, Point, AnimationClock) DrawLine(Pen, Point, AnimationClock, Point, AnimationClock) DrawLine(Pen, Point, AnimationClock, Point, AnimationClock)

Dibuja una línea entre los puntos especificados utilizando el objeto Pen especificado y aplica los relojes de animación especificados.Draws a line between the specified points using the specified Pen and applies the specified animation clocks.

DrawLine(Pen, Point, Point) DrawLine(Pen, Point, Point) DrawLine(Pen, Point, Point) DrawLine(Pen, Point, Point)

Dibuja una línea entre los puntos especificados utilizando el objeto Pen especificado.Draws a line between the specified points using the specified Pen.

DrawRectangle(Brush, Pen, Rect) DrawRectangle(Brush, Pen, Rect) DrawRectangle(Brush, Pen, Rect) DrawRectangle(Brush, Pen, Rect)

Dibuja un rectángulo con los objetos Brush y Pen especificados.Draws a rectangle with the specified Brush and Pen. El lápiz y el pincel pueden ser null.The pen and the brush can be null.

DrawRectangle(Brush, Pen, Rect, AnimationClock) DrawRectangle(Brush, Pen, Rect, AnimationClock) DrawRectangle(Brush, Pen, Rect, AnimationClock) DrawRectangle(Brush, Pen, Rect, AnimationClock)

Dibuja un rectángulo con los objetos Brush y Pen especificados y aplica los relojes de animación especificados.Draws a rectangle with the specified Brush and Pen and applies the specified animation clocks.

DrawRoundedRectangle(Brush, Pen, Rect, AnimationClock, Double, AnimationClock, Double, AnimationClock) DrawRoundedRectangle(Brush, Pen, Rect, AnimationClock, Double, AnimationClock, Double, AnimationClock) DrawRoundedRectangle(Brush, Pen, Rect, AnimationClock, Double, AnimationClock, Double, AnimationClock) DrawRoundedRectangle(Brush, Pen, Rect, AnimationClock, Double, AnimationClock, Double, AnimationClock)

Dibuja un rectángulo redondeado con los objetos Brush y Pen especificados y aplica los relojes de animación especificados.Draws a rounded rectangle with the specified Brush and Pen and applies the specified animation clocks.

DrawRoundedRectangle(Brush, Pen, Rect, Double, Double) DrawRoundedRectangle(Brush, Pen, Rect, Double, Double) DrawRoundedRectangle(Brush, Pen, Rect, Double, Double) DrawRoundedRectangle(Brush, Pen, Rect, Double, Double)

Dibuja un rectángulo redondeado con los objetos Brush y Pen especificados.Draws a rounded rectangle with the specified Brush and Pen.

DrawText(FormattedText, Point) DrawText(FormattedText, Point) DrawText(FormattedText, Point) DrawText(FormattedText, Point)

Dibuja el texto con formato en la ubicación especificada.Draws formatted text at the specified location.

DrawVideo(MediaPlayer, Rect) DrawVideo(MediaPlayer, Rect) DrawVideo(MediaPlayer, Rect) DrawVideo(MediaPlayer, Rect)

Dibuja un vídeo en la región especificada.Draws a video into the specified region.

DrawVideo(MediaPlayer, Rect, AnimationClock) DrawVideo(MediaPlayer, Rect, AnimationClock) DrawVideo(MediaPlayer, Rect, AnimationClock) DrawVideo(MediaPlayer, Rect, AnimationClock)

Dibuja un vídeo en la región especificada y aplica el reloj de animación especificado.Draws a video into the specified region and applies the specified animation clock.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
Pop() Pop() Pop() Pop()

Extrae la última máscara de opacidad, opacidad, recorte, efecto u operación de transformación que se insertó en el contexto de dibujo.Pops the last opacity mask, opacity, clip, effect, or transform operation that was pushed onto the drawing context.

PushClip(Geometry) PushClip(Geometry) PushClip(Geometry) PushClip(Geometry)

Inserta la región de recorte especificada en el contexto de dibujo.Pushes the specified clip region onto the drawing context.

PushEffect(BitmapEffect, BitmapEffectInput) PushEffect(BitmapEffect, BitmapEffectInput) PushEffect(BitmapEffect, BitmapEffectInput) PushEffect(BitmapEffect, BitmapEffectInput)

Inserta el objeto BitmapEffect especificado en el contexto de dibujo.Pushes the specified BitmapEffect onto the drawing context.

PushGuidelineSet(GuidelineSet) PushGuidelineSet(GuidelineSet) PushGuidelineSet(GuidelineSet) PushGuidelineSet(GuidelineSet)

Inserta el objeto GuidelineSet especificado en el contexto de dibujo.Pushes the specified GuidelineSet onto the drawing context.

PushOpacity(Double) PushOpacity(Double) PushOpacity(Double) PushOpacity(Double)

Inserta el valor de opacidad especificado en el contexto de dibujo.Pushes the specified opacity setting onto the drawing context.

PushOpacity(Double, AnimationClock) PushOpacity(Double, AnimationClock) PushOpacity(Double, AnimationClock) PushOpacity(Double, AnimationClock)

Inserta el valor de opacidad especificado en el contexto de dibujo y aplica el reloj de animación especificado.Pushes the specified opacity setting onto the drawing context and applies the specified animation clock.

PushOpacityMask(Brush) PushOpacityMask(Brush) PushOpacityMask(Brush) PushOpacityMask(Brush)

Inserta la máscara de opacidad especificada en el contexto de dibujo.Pushes the specified opacity mask onto the drawing context.

PushTransform(Transform) PushTransform(Transform) PushTransform(Transform) PushTransform(Transform)

Inserta el objeto Transform especificado en el contexto de dibujo.Pushes the specified Transform onto the drawing context.

ToString() ToString() ToString() ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Inherited from Object)
VerifyAccess() VerifyAccess() VerifyAccess() VerifyAccess()

Exige que el subproceso de la llamada tenga acceso a DispatcherObject.Enforces that the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)
VerifyApiNonstructuralChange() VerifyApiNonstructuralChange() VerifyApiNonstructuralChange() VerifyApiNonstructuralChange()

Este miembro es compatible con la infraestructura de WPFWPF y no está diseñado para utilizarse directamente desde el código.This member supports the WPFWPF infrastructure and is not intended to be used directly from your code.

Implementaciones de interfaz explícitas

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

Este miembro es compatible con la infraestructura de Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) y no está diseñado para utilizarse directamente desde el código.This member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.

Propiedades

Dispatcher Dispatcher Dispatcher Dispatcher

Obtiene el objeto Dispatcher al que está asociado DispatcherObject.Gets the Dispatcher this DispatcherObject is associated with.

(Inherited from DispatcherObject)

Se aplica a

Consulte también: