DrawingContext.PushOpacity 方法

定義

將指定的不透明度設定推入繪圖上下文。

多載

名稱 Description
PushOpacity(Double)

將指定的不透明度設定推入繪圖上下文。

PushOpacity(Double, AnimationClock)

將指定的不透明度設定推入繪圖上下文,並套用指定的動畫時鐘。

PushOpacity(Double)

將指定的不透明度設定推入繪圖上下文。

public:
 abstract void PushOpacity(double opacity);
public abstract void PushOpacity(double opacity);
abstract member PushOpacity : double -> unit
Public MustOverride Sub PushOpacity (opacity As Double)

參數

opacity
Double

不透明度因子適用於後續繪製指令。 此因子與先前 PushOpacity(Double) 操作累積。

範例

以下範例展示 PushOpacityPushEffect、 和 Pop 指令。

using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
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));
            }

            // 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))
            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

備註

不透明度會被混合到所有後續繪圖指令中,直到指令 Pop 將其移除。

適用於

PushOpacity(Double, AnimationClock)

將指定的不透明度設定推入繪圖上下文,並套用指定的動畫時鐘。

public:
 abstract void PushOpacity(double opacity, System::Windows::Media::Animation::AnimationClock ^ opacityAnimations);
public abstract void PushOpacity(double opacity, System.Windows.Media.Animation.AnimationClock opacityAnimations);
abstract member PushOpacity : double * System.Windows.Media.Animation.AnimationClock -> unit
Public MustOverride Sub PushOpacity (opacity As Double, opacityAnimations As AnimationClock)

參數

opacity
Double

不透明度因子適用於後續繪製指令。 此因子與先前 PushOpacity(Double) 操作累積。

opacityAnimations
AnimationClock

用來動畫不透明度值的時鐘,或 null 是不動動畫。 這個時鐘必須由 AnimationTimeline 一個能動畫數 Double 值的機器製作。

備註

不透明度會被混合到所有後續繪圖指令中,直到指令 Pop 將其移除。

適用於