GDI+ Ellipses

Ellipses 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 ellipse that we have displayed in the output.

GDI+ Lines

For ellipse 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.

Ellipses are specified like rectangles, with an upper-left point and width and height. When we specify an ellipse 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 code that we use illustrates each of the four methods for drawing ellipse. First, we use the integer coordinate method to draw an orange ellipse. Next, we use a green pen to draw an ellipse using an integer rectangle. Third, we use a yellow pen to draw an ellipse using floating point coordinates. Finally, we use a blue pen to draw the fourth ellipse 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

	// Ellipse 1 - Integer coordinates
	Pen qOrangePen(Color(255, 255, 128, 0), 1.0);
	graphics.DrawEllipse(&qOrangePen, 25, 25, 250, 50);

	// Ellipse 2 - Integer rectangle
	Pen qGreenPen(Color(255, 0, 200, 0), 1.0);
	graphics.DrawEllipse(&qGreenPen, Rect(425, 25, 50, 50));

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

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

    The four color coded drawing commands are given below.

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