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

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

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

How to: Use Antialiasing with Text

Antialiasing refers to the smoothing of jagged edges of drawn graphics and text to improve their appearance or readability. With the managed GDI+ classes, you can render high quality antialiased text, as well as lower quality text. Typically, higher quality rendering takes more processing time than lower quality rendering. To set the text quality level, set the TextRenderingHint property of a Graphics to one of the elements of the TextRenderingHint enumeration

Example

The following code example draws text with two different quality settings.

The following illustration shows the output of the cod example code.

FontFamily fontFamily = new FontFamily("Times New Roman");

Font font = new Font(

fontFamily,

32,

FontStyle.Regular,

GraphicsUnit.Pixel);

SolidBrush solidBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255));

string string1 = "SingleBitPerPixel";

string string2 = "AntiAlias";

e.Graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;

e.Graphics.DrawString(string1, font, solidBrush, new PointF(10, 10));

e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;

e.Graphics.DrawString(string2, font, solidBrush, new PointF(10, 60));

Compiling the Code

The preceding code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of PaintEventHandler.

Сглаживание текста

Сглаживанием называют "смягчение" неровных границ графических элементов и текста для улучшения их внешнего вида или повышения удобочитаемости. Управляемые классы GDI+ позволяют выводить на экран высококачественный сглаженный текст, а также текст низкого качества. Обычно более качественная визуализация требует больших затрат вычислительных ресурсов, чем менее качественная. Для задания уровня качества отображения текста следует установить свойство TextRenderingHint объекта Graphics равным одному из значений перечисления TextRenderingHint.

Пример

В следующем примере кода текст прорисовывается с двумя различными уровнями качества.

На следующем рисунке показан результат выполнения этого кода.

---------

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

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

Constructing and Drawing Curves

GDI+ supports several types of curves: ellipses, arcs, cardinal splines, and Bézier splines. An ellipse is defined by its bounding rectangle; an arc is a portion of an ellipse defined by a starting angle and a sweep angle. A cardinal spline is defined by an array of points and a tension parameter — the curve passes smoothly through each point in the array, and the tension parameter influences the way the curve bends. A Bézier spline is defined by two endpoints and two control points the curve does not pass through the control points, but the control points influence the direction and bend as the curve goes from one endpoint to the other.

How to: Draw Cardinal Splines

A cardinal spline is a curve that passes smoothly through a given set of points. To draw a cardinal spline, create a Graphics object and pass the address of an array of points to the DrawCurve method.

Drawing a Bell-Shaped Cardinal Spline

  • The following example draws a bell-shaped cardinal spline that passes through five designated points. The following illustration shows the curve and five points.

Point[] points = {

new Point(0, 100),

new Point(50, 80),

new Point(100, 20),

new Point(150, 80),

new Point(200, 100)};

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

e.Graphics.DrawCurve(pen, points);