zoukankan      html  css  js  c++  java
  • WPF中的brushes

         颜色

         在WPF中,颜色是由System.Windows.Media下的Color结构体来封装的。Color有三种颜色R,G,B组成。 除了这三个属性,Color还增加了一个alpha管道属性A。它用来表示透明度(Opacity)。值为0时,表示透明(taransparent)。值为255时,表示不透明(opaque)。默认的颜色透明度为opaque。WPF提供了下面的函数来创建颜色。

    Color clr = Color.FromRgb(r, g, b)
    Color clr = Color.FromArgb(a, r, g, b)

         由RGB创建的颜色被称为标准色sRGB。这对于屏幕输出比较适用,而对于一些特殊情况,如打印输出。颜色要求更丰富,此时可以采用scRGB 颜色。这两种颜色之间有对应关系,改变一种得属性也会影响另一种。

         System.Windows.Media提供了一Colors静态类,包含了141种静态属性色。除了Transparent属性返回的颜色透明度为0。其他140种颜色返回的颜色透明度都是255。 如:Color clr = Colors.PapayaWhip;

         当改变一个区域的背景色(Background)时,我们使用画刷(Brush类)。Brush是一个抽象类。它的类层次关系如下:

    Object
        DispatcherObject (abstract)
              DependencyObject
                    Freezable (abstract)
                           Animatable (abstract)
                                 Brush (abstract)
                                       GradientBrush (abstract)
                                             LinearGradientBrush
                                             RadialGradientBrush
                                       SolidColorBrush
                                       TileBrush (abstract)
                                              DrawingBrush
                                              ImageBrush
                                              VisualBrush

    我们在实际应用中使用的是它的实例化继承类。另外,Brushes类也提供了141中静态画刷属性。

         最简单的是SolidColorBrush,它是一个单一色的画刷。使用如下:

    Color clr = Color.FromRgb(0, 255, 255);
    SolidColorBrush brush = new SolidColorBrush(clr);
    Background = brush;
    或者:

    SolidColorBrush brush = new SolidColorBrush();
    brush.Color = Color.FromRgb(128, 0, 128);

    渐进画刷(GradientBrush )

    线性渐变LinearGradientBrush 。这种画刷需要制定一个起点pt1和终点pt2以及两种对应点的颜色col1和col2。颜色在这两点的范围内进行渐变。点位置的确定以画刷要覆盖的对象为参照的,左上角为(0,0),右下角为(1,1)。如对客户区背景进行绘制:

    LinearGradientBrush brush = new LinearGradientBrush(Colors.Red, Colors.Blue,new Point(0,0),new Point(1, 1));
     Background = brush;

    放射渐变RadialGradientBrush。这种画刷以一个中心点为圆心,向外逐渐分散。如:

    LinearGradientBrush brush = new
    LinearGradientBrush();
                brush.StartPoint = new Point(0, 0);
                brush.EndPoint = new Point(1, 0);
                Background = brush;

                // Rainbow mnemonic is the name Roy G.
    Biv.
                brush.GradientStops.Add(new
    GradientStop(Colors.Red, 0));
                brush.GradientStops.Add(new
    GradientStop(Colors.Orange, .17));
                brush.GradientStops.Add(new
    GradientStop(Colors.Yellow, .33));
                brush.GradientStops.Add(new
    GradientStop(Colors.Green, .5));
                brush.GradientStops.Add(new
    GradientStop(Colors.Blue, .67));
                brush.GradientStops.Add(new
    GradientStop(Colors.Indigo, .84));
                brush.GradientStops.Add(new
    GradientStop(Colors.Violet, 1));
            }

         

         

  • 相关阅读:
    springboot CRUD+分页(基于JPA规范)
    springboot中yml配置文件
    springboot中配置切换
    springboot中修改端口和上下文路径
    springboot中全局异常处理器
    springboot热部署
    新的表格展示利器 Bootstrap Table Ⅰ
    关于html转换为pdf案例的一些测试与思考
    java设计模式 策略模式Strategy
    java设计模式 模板方法模式Template Method
  • 原文地址:https://www.cnblogs.com/jyz/p/1291635.html
Copyright © 2011-2022 走看看