-
September 26th, 2012, 09:32 AM
#1
RoundRect
Hi,
I am having some problems with shifting the code from GDI to GDI+.
In the application, the GDI RoundRect function draws the rounded rectangle perfectly but when I use GraphicsPath of GDI+, the corner arcs are not drawn perfectly.
I am using the same coordinates and the same corner ellipse width/height but somehow the corners are not getting overlapped.
Here is my algorithm of RoundRect in GDI+ : -
void DrawRoundedRectangle( IN Rect &rc, IN FLOAT radius, IN COLORREF clr, IN FLOAT lineWidth )
{
float diameter;
diameter = ceil(radius) * 2.0F;
SizeF sizeF(diameter, diameter);
RectF arc((REAL)rc.X, (REAL)rc.Y, sizeF.Width, sizeF.Height);
GraphicsPath path;
path.StartFigure();
path.AddArc(arc, 180, 90);
arc.X = rc.GetRight() - diameter;
path.AddArc(arc, 270, 90);
arc.Y = rc.GetBottom() - diameter;
path.AddArc(arc, 0, 90);
arc.X = (REAL)rc.GetLeft();
path.AddArc(arc, 90, 90);
path.CloseFigure();
Pen p( Color( GetRValue(clr), GetGValue(clr), GetBValue(clr) ), lineWidth );
Graphics *g = Graphics::FromHDC( m_hDC );
g->DrawPath( &p, &path );
delete g;
}
Any help will be highly appreciated.
Thanks & Regards.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|