I have implemented a rounded rectangle extension method, defined here.
public static Graphics DrawRRectangle(this Graphics g, Pen p, int x, int y, int width, int height, int feathering)
{
g.DrawLine(p, x, y + feathering, x, y + height - feathering);
g.DrawBezier(p, new Point(x, y + height - feathering),
new Point(x, y + height - feathering / 2), new Point(x + feathering / 2, y + height),
new Point(x + feathering, y + height));
g.DrawLine(p, x + feathering, y + height , x + width - feathering, y + height);
g.DrawBezier(p, new Point(x + width - feathering, y + height),
new Point(x + width - feathering / 2, y + height), new Point(x + width, y + height - feathering / 2),
new Point(x + width, y + height - feathering));
g.DrawLine(p, x + width, y + height - feathering, x + width, y + feathering);
g.DrawBezier(p, new Point(x + width, y + feathering),
new Point(x + width, y + feathering / 2), new Point(x + width - feathering / 2, y),
new Point(x + width - feathering, y));
g.DrawLine(p, x + width - feathering, y, x + feathering, y);
g.DrawBezier(p, new Point(x + feathering, y),
new Point(x + feathering / 2, y), new Point(x, y + feathering / 2),
new Point(x, y + feathering));
return g;
}
However when I use this method like so
g.DrawRRectangle(p, 100, 100, 1000, 1000, 100);
,
I do not get the outcome I wanted, each of the corners are either misaligned of their pixels do not match up As seen in the images below.
Any suggestions anybody could offer would be helpful, I am unsure if this is a problem with the equations used to generate my curves however this is the first time I am dabbling with graphics, so it could just be my thinking. Thanks.