Blend 类

定义

定义 LinearGradientBrush 对象的混合图案。Defines a blend pattern for a LinearGradientBrush object. 此类不能被继承。This class cannot be inherited.

public ref class Blend sealed
public sealed class Blend
type Blend = class
Public NotInheritable Class Blend
继承
Blend

示例

下面的示例用于在 Windows 窗体环境中使用。The following example is intended to be used in a Windows Forms environment. 它演示了如何将BlendLinearGradientBrush与类结合使用来将椭圆绘制到其颜色混合的屏幕上。It demonstrates how to use the Blend class in conjunction with the LinearGradientBrush class to draw an ellipse to screen that has its colors blended. 椭圆在左侧为蓝色, 在中心处混合为红色, 并在右侧混合回蓝色。The ellipse is blue on the left, blends to red in the center, and blends back to blue on the right. 这是myFactors通过和Positions属性中使用Factors的和myPositions数组中的设置来实现的。This is accomplished through the settings in the myFactors and myPositions arrays used in the Factors and Positions properties. 请注意, Blend名为lgBrush2LinearGradientBrush对象的属性必须等于Blend对象myBlendNote that the Blend property of the LinearGradientBrush object named lgBrush2 must be made equal to the Blend object myBlend.

public:
   void BlendConstExample( PaintEventArgs^ e )
   {
      //Draw ellipse using Blend.
      Point startPoint2 = Point(20,110);
      Point endPoint2 = Point(140,110);
      array<Single>^myFactors = {.2f,.4f,.8f,.8f,.4f,.2f};
      array<Single>^myPositions = {0.0f,.2f,.4f,.6f,.8f,1.0f};
      Blend^ myBlend = gcnew Blend;
      myBlend->Factors = myFactors;
      myBlend->Positions = myPositions;
      LinearGradientBrush^ lgBrush2 =
            gcnew LinearGradientBrush( startPoint2,endPoint2,Color::Blue,Color::Red );
      lgBrush2->Blend = myBlend;
      Rectangle ellipseRect2 = Rectangle(20,110,120,80);
      e->Graphics->FillEllipse( lgBrush2, ellipseRect2 );

      // End example.
   }
public void BlendConstExample(PaintEventArgs e)
{
             
    //Draw ellipse using Blend.
    Point startPoint2 = new Point(20, 110);
    Point endPoint2 = new Point(140, 110);
    float[] myFactors = {.2f,.4f,.8f,.8f,.4f,.2f};
    float[] myPositions = {0.0f,.2f,.4f,.6f,.8f,1.0f};
    Blend myBlend = new Blend();
    myBlend.Factors = myFactors;
    myBlend.Positions = myPositions;
    LinearGradientBrush lgBrush2 = new LinearGradientBrush(
        startPoint2,
        endPoint2,
        Color.Blue,
        Color.Red);
    lgBrush2.Blend = myBlend;
    Rectangle ellipseRect2 = new Rectangle(20, 110, 120, 80);
    e.Graphics.FillEllipse(lgBrush2, ellipseRect2);
             
    // End example.
}
Public Sub BlendConstExample(ByVal e As PaintEventArgs)

    ' Draw ellipse using Blend.
    Dim startPoint2 As New Point(20, 110)
    Dim endPoint2 As New Point(140, 110)
    Dim myFactors As Single() = {0.2F, 0.4F, 0.8F, 0.8F, 0.4F, 0.2F}
    Dim myPositions As Single() = {0.0F, 0.2F, 0.4F, 0.6F, 0.8F, 1.0F}
    Dim myBlend As New Blend
    myBlend.Factors = myFactors
    myBlend.Positions = myPositions
    Dim lgBrush2 As New LinearGradientBrush(startPoint2, endPoint2, _
    Color.Blue, Color.Red)
    lgBrush2.Blend = myBlend
    Dim ellipseRect2 As New Rectangle(20, 110, 120, 80)
    e.Graphics.FillEllipse(lgBrush2, ellipseRect2)
End Sub

注解

渐变通常用于平滑形状内部。Gradients are commonly used to smoothly shade the interiors of shapes. 混合模式由两个数组 (FactorsPositions) 定义, 每个数组都包含相同数量的元素。A blend pattern is defined by two arrays (Factors and Positions) that each contain the same number of elements. Positions数组的每个元素都表示沿渐变线的距离的比例。Each element of the Positions array represents a proportion of the distance along the gradient line. Factors数组中的每个元素都表示渐变 blend 中沿Positions数组中相应元素表示的位置上的起始和结束颜色的比例。Each element of the Factors array represents the proportion of the starting and ending colors in the gradient blend at the position along the gradient line represented by the corresponding element in the Positions array.

例如, 如果PositionsFactors数组的对应元素分别为0.2 和 0.3, 则在100像素线上, 对于从蓝到红色的线性渐变, 沿该行的颜色20像素 (距离的 20%) 包含 30%蓝和 70% 红色。For example, if corresponding elements of the Positions and Factors arrays are 0.2 and 0.3, respectively, for a linear gradient from blue to red along a 100-pixel line, the color 20 pixels along that line (20 percent of the distance) consists of 30 percent blue and 70 percent red.

构造函数

Blend()

初始化 Blend 类的新实例。Initializes a new instance of the Blend class.

Blend(Int32)

用指定的因子和位置的数目初始化 Blend 类的新实例。Initializes a new instance of the Blend class with the specified number of factors and positions.

属性

Factors

获取或设置用于渐变的混合因子数组。Gets or sets an array of blend factors for the gradient.

Positions

获取或设置渐变的混合位置的数组。Gets or sets an array of blend positions for the gradient.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于