Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CSharp_Graphics.doc
Скачиваний:
20
Добавлен:
16.11.2019
Размер:
3.1 Mб
Скачать

Создание диагональных линейных градиентов

  • Передайте непрозрачный синий и непрозрачный зеленый цвета в качестве соответственно третьего и четвертого аргументов.

-----------------

How to: Create a Path Gradient

The PathGradientBrush class allows you to customize the way you fill a shape with gradually changing colors. For example, you can specify one color for the center of a path and another color for the boundary of a path. You can also specify separate colors for each of several points along the boundary of a path.

Note:

In GDI+, a path is a sequence of lines and curves maintained by a GraphicsPath object.

To fill an ellipse with a path gradient

  • The following example fills an ellipse with a path gradient brush. The center color is set to blue and the boundary color is set to aqua. The following illustration shows the filled ellipse.

By default, a path gradient brush does not extend outside the boundary of the path. If you use the path gradient brush to fill a figure that extends beyond the boundary of the path, the area of the screen outside the path will not be filled.

// Create a path that consists of a single ellipse.

GraphicsPath path = new GraphicsPath();

path.AddEllipse(0, 0, 140, 70);

// Use the path to construct a brush.

PathGradientBrush pthGrBrush = new PathGradientBrush(path);

// Set the color at the center of the path to blue.

pthGrBrush.CenterColor = Color.FromArgb(255, 0, 0, 255);

// Set the color along the entire boundary

// of the path to aqua.

Color[] colors = { Color.FromArgb(255, 0, 255, 255) };

pthGrBrush.SurroundColors = colors;

e.Graphics.FillEllipse(pthGrBrush, 0, 0, 140, 70);

Создание градиента вдоль контура

Класс PathGradientBrush позволяет настраивать способ заливки фигуры плавно меняющимися цветами. Например, можно указать один цвет для центра контура, а другой — для границы контура. Можно также определить отдельные цвета для каждой из нескольких точек на границе контура.

Примечание.

В интерфейсе GDI+ контур представляет собой последовательность линий и кривых, поддерживаемых объектом GraphicsPath.

Заливка эллипса с использованием градиента контура

  • В следующем примере осуществляется заливка эллипса с помощью кисти градиента контура. Для центра установлен синий цвет, а для границы — голубой. Эллипс после заливки представлен на следующем рисунке.

По умолчанию кисть градиента контура не расширяется на области вне границы этого контура. Если кисть градиента контура используется для заливки фигуры, которая заходит за границу данного контура, области вне границы контура не заливаются.

-------------

To specify points on the boundary

  • The following example constructs a path gradient brush from a star-shaped path. The code sets the CenterColor property, which sets the color at the centroid of the star to red. Then the code sets the SurroundColors property to specify various colors (stored in the colors array) at the individual points in the points array. The final code statement fills the star-shaped path with the path gradient brush.

// Put the points of a polygon in an array.

Point[] points = {

new Point(75, 0),

new Point(100, 50),

new Point(150, 50),

new Point(112, 75),

new Point(150, 150),

new Point(75, 100),

new Point(0, 150),

new Point(37, 75),

new Point(0, 50),

new Point(50, 50)};

// Use the array of points to construct a path.

GraphicsPath path = new GraphicsPath();

path.AddLines(points);

// Use the path to construct a path gradient brush.

PathGradientBrush pthGrBrush = new PathGradientBrush(path);

// Set the color at the center of the path to red.

pthGrBrush.CenterColor = Color.FromArgb(255, 255, 0, 0);

// Set the colors of the points in the array.

Color[] colors = {

Color.FromArgb(255, 0, 0, 0),

Color.FromArgb(255, 0, 255, 0),

Color.FromArgb(255, 0, 0, 255),

Color.FromArgb(255, 255, 255, 255),

Color.FromArgb(255, 0, 0, 0),

Color.FromArgb(255, 0, 255, 0),

Color.FromArgb(255, 0, 0, 255),

Color.FromArgb(255, 255, 255, 255),

Color.FromArgb(255, 0, 0, 0),

Color.FromArgb(255, 0, 255, 0)};

pthGrBrush.SurroundColors = colors;

// Fill the path with the path gradient brush.

e.Graphics.FillPath(pthGrBrush, path);