zoukankan      html  css  js  c++  java
  • DrawingContext.Pop Method

    The following example shows the effect of the Pop command.

    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;
    
            }
    
    
    
    
        }
    
    }

     

     

    The following illustration shows this example's output:

    Rectangles drawn with different opacity values

  • 相关阅读:
    转载 NPOI.dll 用法。单元格,样式,字体,颜色,行高,宽度。读写excel
    Microsoft Visual SourceSafe 6.0 无法关联项目
    dynamic json
    c#查找string数组的某一个值的索引
    C#中 删除掉字符串数组中的空字符串
    c# 比较两个数组每一个值是否相等
    c#比较两个数组的差异
    C#动态操作DataTable(新增行、列、查询行、列等)
    C#数字转字母,ASCII码转换
    c#中使程序跳到指定行中
  • 原文地址:https://www.cnblogs.com/xpvincent/p/4276456.html
Copyright © 2011-2022 走看看