DrawingGroup.Opacity 속성

정의

DrawingGroup의 불투명도를 가져오거나 설정합니다.

public:
 property double Opacity { double get(); void set(double value); };
public double Opacity { get; set; }
member this.Opacity : double with get, set
Public Property Opacity As Double

속성 값

Double

이 값은 0 이상 1 이하이며 이 DrawingGroup의 불투명도를 설명합니다. 기본값은 1입니다.

예제

불투명도 수정 하는 방법을 보여 주는이 예제는 Drawing합니다. DrawingGroup 클래스의 유일한 형식인 Drawing 가 있는 개체는 Opacity 속성입니다.

불투명도 변경 하는 Drawing 개체에 추가 하는 DrawingGroup 설정를 Opacity 의 속성은 DrawingGroup 개체.

Opacity 설정를 DrawingGroup 개체; 자식 그리기의 불투명도 곱한 예를 들어 경우는 DrawingGroupOpacity 0.5의 포함는 GeometryDrawing 는 50% 불투명 Brush, 브러시는 25 % 불투명 (0.5 * 0.5)입니다.

선택 부분 그리기의 불투명도 변경 하려면 사용는 OpacityMask합니다.

다음 예에서는 DrawingGroup 여러 결합 GeometryDrawing 개체입니다. 또한의 불투명도 설정의 DrawingGroup 0.25는 그림 25% 불투명 개체입니다.

이 그림과 합니다 DrawingGroup 전과 후 해당 Opacity 0.25로 설정 됩니다.

여러 불투명도 설정의 DrawingGroup

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

namespace SDKSample
{
    public class OpacityExample : Page
    {
        public OpacityExample()
        {

            //
            // Create a GeometryDrawing.
            //

            // Define the drawing's contents.
            PathFigure pLineFigure = new PathFigure();
            pLineFigure.StartPoint = new Point(25, 25);
            PolyLineSegment pLineSegment = new PolyLineSegment();
            pLineSegment.Points.Add(new Point(0, 50));
            pLineSegment.Points.Add(new Point(25, 75));
            pLineSegment.Points.Add(new Point(50, 50));
            pLineSegment.Points.Add(new Point(25, 25));
            pLineSegment.Points.Add(new Point(25, 0));
            pLineFigure.Segments.Add(pLineSegment);
            PathGeometry pGeometry = new PathGeometry();
            pGeometry.Figures.Add(pLineFigure);

            GeometryDrawing drawing1 = new GeometryDrawing(
                    Brushes.Lime,
                    new Pen(Brushes.Black, 10),
                    pGeometry
                );

            //
            // Create another GeometryDrawing.
            //
            GeometryDrawing drawing2 = new GeometryDrawing(
                    Brushes.Lime,
                    new Pen(Brushes.Black, 2),
                    new EllipseGeometry(new Point(10, 10), 5, 5)
                );

            // Create the DrawingGroup and add the
            // geometry drawings.
            DrawingGroup aDrawingGroup = new DrawingGroup();
            aDrawingGroup.Children.Add(drawing1);
            aDrawingGroup.Children.Add(drawing2);

            //
            // Set the opacity of the DrawingGroup to 0.25.
            //
            aDrawingGroup.Opacity = 0.25;

            // Use an Image control and a DrawingImage to
            // display the drawing.
            DrawingImage aDrawingImage = new DrawingImage(aDrawingGroup);

            // Freeze the DrawingImage for performance benefits.
            aDrawingImage.Freeze();

            Image anImage = new Image();
            anImage.Source = aDrawingImage;
            anImage.Stretch = Stretch.None;
            anImage.HorizontalAlignment = HorizontalAlignment.Left;

            // Create a border around the images and add it to the
            // page.
            Border imageBorder = new Border();
            imageBorder.BorderBrush = Brushes.Gray;
            imageBorder.BorderThickness = new Thickness(1);
            imageBorder.VerticalAlignment = VerticalAlignment.Top;
            imageBorder.HorizontalAlignment = HorizontalAlignment.Left;
            imageBorder.Margin = new Thickness(20);
            imageBorder.Child = anImage;

            this.Background = Brushes.White;
            this.Margin = new Thickness(20);
            this.Content = imageBorder;
        }
    }
}
<Page 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" 
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  mc:Ignorable="PresentationOptions"
  Background="White" Margin="20">
  <Border BorderBrush="Gray" BorderThickness="1" 
    HorizontalAlignment="Left" VerticalAlignment="Top"
    Margin="20">
    <Image Stretch="None">
      <Image.Source>
        <DrawingImage PresentationOptions:Freeze="True">
          <DrawingImage.Drawing>

            <!-- The drawing group, with an Opacity of 0.25. -->
            <DrawingGroup Opacity="0.25">
              <GeometryDrawing Brush="Lime" Geometry="M 25,25 L 0,50 25,75 50,50 25,25 25,0">
                <GeometryDrawing.Pen>
                  <Pen Thickness="10" Brush="Black" />
                </GeometryDrawing.Pen>
              </GeometryDrawing>
              <GeometryDrawing Brush="Lime">
                <GeometryDrawing.Geometry>
                  <EllipseGeometry Center="10,10" RadiusX="5" RadiusY="5" />
                </GeometryDrawing.Geometry>
                <GeometryDrawing.Pen>
                  <Pen Thickness="2" Brush="Black" />
                </GeometryDrawing.Pen>
              </GeometryDrawing>
            </DrawingGroup>
          </DrawingImage.Drawing>
        </DrawingImage>
      </Image.Source>
    </Image>
  </Border>


</Page>

설명

1 지정 된 DrawingGroup 은 완전히 불투명 합니다; 값 0 완전히 투명 하 게 임을 지정 합니다. 0 0으로 처리 되 고 1 보다 큰 값 보다 작은 값은 1로 처리 합니다.

불투명도 제어 하는 또 다른 방법은 GeometryDrawing 지정 하는 것은 Opacity 의 해당 Brush합니다.

DrawingGroup 작업이 아래 순서 대로 적용 됩니다.

  1. OpacityMask

  2. Opacity

  3. BitmapEffect

  4. ClipGeometry

  5. GuidelineSet

  6. Transform

종속성 속성 정보

식별자 필드 OpacityProperty
메타 데이터 속성 설정 true 없음

적용 대상

추가 정보