C#画圆角矩形的方法
程序员文章站
2022-03-22 14:34:10
本文实例讲述了c#画圆角矩形的方法。分享给大家供大家参考。具体实现方法如下:
protected void page_load(object sender, ev...
本文实例讲述了c#画圆角矩形的方法。分享给大家供大家参考。具体实现方法如下:
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(0,0,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 pen,rectangle rect, int cornerradius) { using (graphicspath path = createroundedrectanglepath(rect, cornerradius)) { g.drawpath(pen, path); } } public static void fillroundrectangle(graphics g, brush 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; }
希望本文所述对大家的c#程序设计有所帮助。
上一篇: jQuery实现朋友圈查看图片
下一篇: PHP数组访问常用方法解析