Protected void page_load (Object sender, eventargs E)
{
Bitmap Bm = new Bitmap (800,600 );
Graphics G = graphics. fromimage (BM );
G. fillrectangle (brushes. White, new rectangle (800,600 ));
Fillroundrectangle (G, brushes. Plum, new rectangle (100,100,100,100), 8 );
Drawroundrectangle (G, pens. Yellow, new rectangle (100,100,100,100), 8 );
BM. Save (response. outputstream, imageformat. JPEG );
G. Dispose ();
BM. Dispose ();
}
Public static void drawroundrectangle (Graphics g, Pen, rectangle rect, int cornerradius)
{
Using (graphicspath Path = createroundedrectanglepath (rect, cornerradius ))
{
G. drawpath (pen, PATH );
}
}
Public static void fillroundrectangle (Graphics g, brush, rectangle rect, int cornerradius)
{
Using (graphicspath Path = createroundedrectanglepath (rect, cornerradius ))
{
G. fillpath (brush, PATH );
}
}
Internal static graphicspath createroundedrectanglepath (rectangle rect, int cornerradius)
{
Graphicspath roundedrect = new graphicspath ();
Roundedrect. addarc (rect. X, rect. Y, cornerradius * 2, cornerradius * 2,180, 90 );
Roundedrect. addline (rect. x + cornerradius, rect. Y, rect. Right-cornerradius * 2, rect. y );
Roundedrect. addarc (rect. x + rect. Width-cornerradius * 2, rect. Y, cornerradius * 2, cornerradius * 2,270, 90 );
Roundedrect. addline (rect. Right, rect. Y + cornerradius * 2, rect. Right, rect. Y + rect. Height-cornerradius * 2 );
Roundedrect. addarc (rect. X + rect. width-cornerradius * 2, rect. Y + rect. height-cornerradius * 2, cornerradius * 2, cornerradius * 2, 0, 90 );
Roundedrect. addline (rect. Right-cornerradius * 2, rect. Bottom, rect. x + cornerradius * 2, rect. Bottom );
Roundedrect. addarc (rect. X, rect. Bottom-cornerradius * 2, cornerradius * 2, cornerradius * 2, 90, 90 );
Roundedrect. addline (rect. X, rect. Bottom-cornerradius * 2, rect. X, rect. Y + cornerradius * 2 );
Roundedrect. closefigure ();
Return roundedrect;
}