GDI+ C++

Bezier Curves

Bezier curves can be created via six different function calls in GDI+. Coordinates can be specified as integers or floating-point numbers, and each method has three corresponding function calls. For either of these, two of the methods draw a single curve and the third can be used to draw a continuous set of curves. The six different methods are illustrated in the program that we have written, and each one corresponds to the curve or string of curves that we have displayed in the output.

GDI+ Bezier Curves

For a single bezier curve, we can specify the points in coordinates or point 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 point types are Point for integers and PointF for the floating-point type; each has two coordinates.

The code that we use illustrates each of the six methods for drawing lines. First, we use the integer coordinate method to draw an orange curve. Next, we use a green pen to draw a curve using four integer points. Third, we use a red pen to draw three continuous curves using an array of ten integer points. Fourth, we use a yellow pen to draw a bezier curve using floating point coordinates. Fifth, we use a blue pen to draw a bezier curve using floating-point based points. Finally, the sixth command draws a string of four curves in purple that form a circle, using an array of floating-point points.

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

	// Bezier Curve 1 - Integer coordinates
	Pen qOrangePen(Color(255, 255, 128, 0), 1.0);
	graphics.DrawBezier(&qOrangePen, 25, 25, 100, 25, 100, 75, 175, 75);

	// Bezier Curve 2 - Integer points
	Pen qGreenPen(Color(255, 0, 200, 0), 1.0);
	graphics.DrawBezier(&qGreenPen, Point(225, 50), Point(300, 0),
		Point(300, 100), Point(375, 50));

	// Bezier Curves 1 - An Array of integer points
	Pen qRedPen(Color(255, 255, 0, 0), 1.0);
	Point qaPoints[10] = { Point(420, 25), Point(445, 25), Point(445, 75), Point(470, 75),
		Point(495, 75), Point(495, 25), Point(520, 25),
		Point(545, 25), Point(545, 75), Point(570, 75)};
	graphics.DrawBeziers(&qRedPen, qaPoints, 10);

	// Bezier Curve 3 - Floating-point coordinates
	Pen qYellowPen(Color(255, 200, 200, 0), 1.0);
	graphics.DrawBezier(&qYellowPen, 35.3f, 120.1f, 189.3f, 105.6f,
		29.3f, 195.6f, 192.3f, 175.6f);

	// Bezier Curve 4 - Floating-point points
	Pen qBluePen(Color(255, 0, 0, 255), 1.0);
	graphics.DrawBezier(&qBluePen, PointF(229.3, 187.6), PointF(235.3,120.1),
		PointF(389.3, 105.6), PointF(374.3, 185.6));

	// Bezier Curves 2 - An Array of floating-point points
	Pen qPurplePen(Color(255, 200, 0, 240), 1.0);
	float fDelta = 28.0f;
	PointF qaPointsF[13] = { PointF(450.0, 150.0), PointF(450.0, 150.0 - fDelta),
		PointF(500.0 - fDelta, 100.0), PointF(500.0, 100.0),
		PointF(500.0 + fDelta, 100.0), PointF(550.0, 150.0 - fDelta), PointF(550.0, 150.0),
		PointF(550.0, 150.0 + fDelta), PointF(500.0 + fDelta, 200.0), PointF(500.0, 200.0),
		PointF(500.0 - fDelta, 200.0), PointF(450.0, 150.0 + fDelta), PointF(450.0, 150.0)};
	graphics.DrawBeziers(&qPurplePen, qaPointsF, 13);
  	

    The six line drawing commands are given below and are color coded.

  1. Integer coordinates
    Pen qOrangePen(Color(255, 255, 128, 0), 1.0);
    graphics.DrawBezier(&qOrangePen, 25, 25, 100, 25, 100, 75, 175, 75);
      	
  2. Integer points
    Pen qGreenPen(Color(255, 0, 200, 0), 1.0);
    graphics.DrawBezier(&qGreenPen, Point(225, 50), Point(300, 0),
    	Point(300, 100), Point(375, 50));
      	
  3. An array of integer points
    Pen qRedPen(Color(255, 255, 0, 0), 1.0);
    Point qaPoints[10] = { Point(420, 25), Point(445, 25), Point(445, 75), Point(470, 75),
    	Point(495, 75), Point(495, 25), Point(520, 25),
    	Point(545, 25), Point(545, 75), Point(570, 75)};
    graphics.DrawBeziers(&qRedPen, qaPoints, 10);
      	
  4. Floating-point coordinates
    Pen qYellowPen(Color(255, 200, 200, 0), 1.0);
    graphics.DrawBezier(&qYellowPen, 35.3f, 120.1f, 189.3f, 105.6f,
    	29.3f, 195.6f, 192.3f, 175.6f);
      	
  5. Floating-point points
    Pen qBluePen(Color(255, 0, 0, 255), 1.0);
    graphics.DrawBezier(&qBluePen, PointF(229.3, 187.6), PointF(235.3,120.1),
    	PointF(389.3, 105.6), PointF(374.3, 185.6));
      	
  6. An array of floating-point points
    Pen qPurplePen(Color(255, 200, 0, 240), 1.0);
    float fDelta = 28.0f;
    PointF qaPointsF[13] = { PointF(450.0, 150.0), PointF(450.0, 150.0 - fDelta),
    	PointF(500.0 - fDelta, 100.0), PointF(500.0, 100.0),
    	PointF(500.0 + fDelta, 100.0), PointF(550.0, 150.0 - fDelta), PointF(550.0, 150.0),
    	PointF(550.0, 150.0 + fDelta), PointF(500.0 + fDelta, 200.0), PointF(500.0, 200.0),
    	PointF(500.0 - fDelta, 200.0), PointF(450.0, 150.0 + fDelta), PointF(450.0, 150.0)};
    graphics.DrawBeziers(&qPurplePen, qaPointsF, 13);
      	
 

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