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

Компиляция кода

Предыдущий пример предназначен для работы с Windows Forms, для него необходим объект PaintEventArgs e, передаваемый в качестве параметра обработчику события Paint.

How to: Fill Open Figures

You can fill a path by passing a GraphicsPath object to the FillPath method. The FillPath method fills the path according to the fill mode (alternate or winding) currently set for the path. If the path has any open figures, the path is filled as if those figures were closed. GDI+ closes a figure by drawing a straight line from its ending point to its starting point.

Example

The following example creates a path that has one open figure (an arc) and one closed figure (an ellipse). The FillPath method fills the path according to the default fill mode, which is Alternate.

The following illustration shows the output of the example code. Note that the path is filled (according to Alternate) as if the open figure were closed by a straight line from its ending point to its starting point.

GraphicsPath path = new GraphicsPath();

// Add an open figure.

path.AddArc(0, 0, 150, 120, 30, 120);

// Add an intrinsically closed figure.

path.AddEllipse(50, 50, 50, 100);

Pen pen = new Pen(Color.FromArgb(128, 0, 0, 255), 5);

SolidBrush brush = new SolidBrush(Color.Red);

// The fill mode is FillMode.Alternate by default.

e.Graphics.FillPath(brush, path);

e.Graphics.DrawPath(pen, path);

Compiling the Code

The preceding example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler.

Заливка открытых фигур

Для заливки контура необходимо передать объект GraphicsPath методу FillPath. Метод FillPath осуществляет заливку контура в соответствии с режимом заливки (альтернативным режимом или режимом заполнения), установленным для этого контура. Если контур содержит незамкнутые фигуры, то заливка происходит так, как если бы фигуры были замкнутыми. Интерфейс GDI+ замыкает фигуру с помощью прямой линии, соединяющей начальную и конечную точки.

Пример

В следующем примере создается контур, содержащий одну открытую фигуру (дугу) и одну замкнутую фигуру (эллипс). Метод FillPath производит заливку пути в соответствии с режимом заливки, принятым по умолчанию, т. е. Alternate.

На следующем рисунке показан результат выполнения примера кода. Следует обратить внимание, что контур заполняется (в соответствии с Alternate) так, как будто открытая фигура замкнута с помощью прямого отрезка, соединяющего ее конечную и начальную точки.

-------

Компиляция кода

Предыдущий пример предназначен для работы с Windows Forms, для него необходим объект PaintEventArgs e, передаваемый в качестве параметра обработчику события Paint.

How to: Flatten a Curved Path into a Line

A GraphicsPath object stores a sequence of lines and Bézier splines. You can add several types of curves (ellipses, arcs, cardinal splines) to a path, but each curve is converted to a Bézier spline before it is stored in the path. Flattening a path consists of converting each Bézier spline in the path to a sequence of straight lines. The following illustration shows a path before and after flattening.

To Flatten a Path

  • call the Flatten method of a GraphicsPath object. The Flatten method receives a flatness argument that specifies the maximum distance between the flattened path and the original path.

Using Transformations in Managed GDI+

Affine transformations include rotating, scaling, reflecting, shearing, and translating. In GDI+, the Matrix class provides the foundation for performing affine transformations on vector drawings, images, and text.

Using the World Transformation

The world transformation is a property of the Graphics class. The numbers that specify the world transformation are stored in a Matrix object, which represents a 3×3 matrix. The Matrix and Graphics classes have several methods for setting the numbers in the world transformation matrix.