Export (0) Print
Expand All

Blend Class

Defines a blend pattern for a LinearGradientBrush object. This class cannot be inherited.

Namespace: System.Drawing.Drawing2D
Assembly: System.Drawing (in system.drawing.dll)

public sealed class Blend
public final class Blend
public final class Blend
Not applicable.

Gradients are commonly used to smoothly shade the interiors of shapes. A blend pattern is defined by two arrays (Factors and Positions) that each contain the same number of elements. Each element of the Positions array represents a proportion of the distance along the gradient line. 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.

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.

The following example is intended to be used in a Windows Forms environment. 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. This is accomplished through the settings in the myFactors and myPositions arrays used in the Factors and Positions properties. Note 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 = 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 void BlendConstExample(PaintEventArgs e)
{
    //Draw ellipse using Blend.
    Point startPoint2 = new Point(20, 110);
    Point endPoint2 = new Point(140, 110);
    float myFactors[] =  { 0.2F, 0.4F, 0.8F, 0.8F, 0.4F, 0.2F };
    float myPositions[] =  { 0.0F, 0.2F, 0.4F, 0.6F, 0.8F, 1.0F };
    Blend myBlend = new Blend();

    myBlend.set_Factors(myFactors);
    myBlend.set_Positions(myPositions);

    LinearGradientBrush lgBrush2 = new LinearGradientBrush(startPoint2, 
        endPoint2, Color.get_Blue(), Color.get_Red());

    lgBrush2.set_Blend(myBlend);

    Rectangle ellipseRect2 = new Rectangle(20, 110, 120, 80);

    e.get_Graphics().FillEllipse(lgBrush2, ellipseRect2);
} //BlendConstExample
// End example.

System.Object
  System.Drawing.Drawing2D.Blend

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft