GDI+ C++

Arcs

Arcs can be created via four different function calls in GDI+. Coordinates can be specified as integers or floating-point numbers, and each method has two corresponding function calls. For either of these, one of the methods uses coordinates and the other uses a rectangle object. The four different methods are illustrated in the program that we have written, and each one corresponds to an arc that we have displayed in the output.

GDI+ Lines

For arc drawing, we can specify the bounds as coordinate values or inside rectangle objects. The integer coordinates are specified as INT type, while the floating-point coordinates are specified as REAL type. These correspond to the native int and float types. The rectangle types are Rect for integers and RectF for the floating-point type; each has four coordinates.

Arcs are specified like rectangles, with an upper-left point and width and height. When we specify an arc with coordinates, the first coordinate is the x-ccordinate of the upper-left corner, the second is the y-coordinate of the upper-left corner, the third is the width of the bounding rectangle, and the fourth is the height of the bounding rectangle. Rectangles are specified the same way.

The specification of an arc is just like an ellipse, except for the last two arguments. The last two arguments are always floating-point REAL values and specify the start angle and the sweep angle for the arc. The start angle indicates where the angle starts and the sweep angle indicates how large the arc should be. Angles are specified with zero as the right-most point, as usual for angles in mathematics. However, angle values are specified with the opposite orientation (clockwise, rather than counterclockwise), but we can use negative values to specify the counterclockwise direction.

The code that we use illustrates each of the four methods for drawing arcs. First, we use the integer coordinate method to draw an orange arc. Next, we use a green pen to draw an arc using an integer rectangle. Third, we use a yellow pen to draw an arc using floating point coordinates. Finally, we use a blue pen to draw the fourth arc using a floating-point based rectangle.

The drawing code is given here.

	Graphics graphics(hdc);
	// This makes the drawing smooth, rather than jagged.
	graphics.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
	// Pens have ARGB color channels and curve width parameters

	// Arc 1 - Integer coordinates
	Pen qOrangePen(Color(255, 255, 128, 0), 1.0);
	graphics.DrawArc(&qOrangePen, 25, 25, 250, 50, 0.0f, 225.0f);

	// Arc 2 - Integer rectangle
	Pen qGreenPen(Color(255, 0, 200, 0), 1.0);
	graphics.DrawArc(&qGreenPen, Rect(425, 25, 50, 50), -90.0f, -270.0f);

	// Arc 3 - Floating-point coordinates
	Pen qYellowPen(Color(255, 200, 200, 0), 1.0);
	graphics.DrawArc(&qYellowPen, 140.0f, 115.0f, 20.0f, 70.0f, 90.0f, 270.0f);

	// Arc 4 - Floating-point rectangle
	Pen qBluePen(Color(255, 0, 0, 255), 1.0);
	graphics.DrawArc(&qBluePen, RectF(350.0f, 115.0f, 200.0f, 70.0f), 0.0f, -225.0f);
  	

    The four color coded drawing commands are given below.

  1. Integer coordinates
    Pen qOrangePen(Color(255, 255, 128, 0), 1.0);
    graphics.DrawArc(&qOrangePen, 25, 25, 250, 50, 0.0f, 225.0f);
      	
  2. Integer rectangle
    Pen qGreenPen(Color(255, 0, 200, 0), 1.0);
    graphics.DrawArc(&qGreenPen, Rect(425, 25, 50, 50), -90.0f, -270.0f);
      	
  3. Floating-point coordinates
    Pen qYellowPen(Color(255, 200, 200, 0), 1.0);
    graphics.DrawArc(&qYellowPen, 140.0f, 115.0f, 20.0f, 70.0f, 90.0f, 270.0f);
      	
  4. Floating-point rectangle
    Pen qBluePen(Color(255, 0, 0, 255), 1.0);
    graphics.DrawArc(&qBluePen, RectF(350.0f, 115.0f, 200.0f, 70.0f), 0.0f, -225.0f);
      	
 

© 2007–2024 XoaX.net LLC. All rights reserved.