Partager via


DrawingContext.Pop Méthode

Définition

Extrait par un pop le dernier masque d'opacité, opacité, clip, effet ou opération de transformation qui a fait l'objet d'un push sur le contexte de dessin.

public:
 abstract void Pop();
public abstract void Pop ();
abstract member Pop : unit -> unit
Public MustOverride Sub Pop ()

Exemples

L’exemple suivant montre l’effet de la Pop commande.

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

namespace SDKSample
{

    public class PopExample : Page
    {

        public PopExample()
        {
            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));

                // Push an opacity change of 0.5. 
                // The opacity of each subsequent drawing will
                // will be multiplied by 0.5. Note that
                // push operations are cumulative (until they are
                // popped). 
                dc.PushOpacity(0.5);

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

                // Changes the opacity back to 0.5.
                dc.Pop();

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

                // Changes the opacity back to 1.0.
                dc.Pop();

                // This rectangle is drawn at 100% opacity.
                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

Namespace SDKSample


    Public Class PopExample
        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))

                ' Push an opacity change of 0.5. 
                ' The opacity of each subsequent drawing will
                ' will be multiplied by 0.5. Note that
                ' push operations are cumulative (until they are
                ' popped). 
                dc.PushOpacity(0.5)

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

                ' Changes the opacity back to 0.5.
                dc.Pop()

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

                ' Changes the opacity back to 1.0.
                dc.Pop()

                ' This rectangle is drawn at 100% opacity.
                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

L’illustration suivante montre la sortie de cet exemple :

Rectangles dessinés avec différentes valeurs d'opacité

Remarques

Une fois qu’une opération est déclenchée, elle n’est plus appliquée aux commandes de dessin suivantes.

S’applique à