Martin Nijhoff
Martin Nijhoff

Reputation: 73

How to draw the outline of a thick line?

I want to draw the outline of a thick line, that was drawn with a geometric pen. The line can be a polygon or a curve, but for simplicity I'm using a straight line.

enter image description here

Given two POINT variables A and B, the following code draws a black 16-pixel wide line with round endcaps between A and B:

LOGBRUSH lb = {BS_SOLID, clBlack, 0};

HPEN Pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_ROUND, 16, &lb, 0, NULL);

HPEN OldPen = SelectObject(DC, Pen);

MoveToEx(DC, A.x, A.y, NULL);
LineTo  (DC, B.x, B.y);

SelectObject(DC, OldPen);

The idea was to place the above code between BeginPath(DC) and EndPath(DC), and use StrokePath(DC) to draw the outline of the thick line, using a 1-pixel pen. But, instead of drawing the outline (the green line in the image), it draws a 1-pixel line between A and B (the red line in the image).

Is there any way to fix this?

Upvotes: 1

Views: 246

Answers (1)

rustyx
rustyx

Reputation: 85382

Use WidenPath after defining the path:

The WidenPath function redefines the current path as the area that would be painted if the path were stroked using the pen currently selected into the given device context.

Upvotes: 1

Related Questions