C#畫圓角矩形的方法
更新時間:2015年05月08日 15:18:10 作者:xujh
這篇文章主要介紹了C#畫圓角矩形的方法,涉及C#繪圖的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了C#畫圓角矩形的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
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#程序設(shè)計有所幫助。
您可能感興趣的文章:
相關(guān)文章
C#中的靜態(tài)字段double.Epsilon實例詳解
double.Epsilon 是C#中的一個靜態(tài)字段,表示 double 數(shù)據(jù)類型的最小可表示的正數(shù)值,這篇文章主要介紹了C#中的靜態(tài)字段double.Epsilon的相關(guān)知識,需要的朋友可以參考下2024-01-01C#實現(xiàn)把txt文本數(shù)據(jù)快速讀取到excel中
這篇文章主要介紹了C#實現(xiàn)把txt文本數(shù)據(jù)快速讀取到excel中,本文直接給出示例代碼,需要的朋友可以參考下2015-06-06C#利用OpenCvSharp實現(xiàn)玉米粒計數(shù)
這篇文章主要為大家詳細(xì)介紹了C#如何結(jié)合OpenCVSharp4實現(xiàn)玉米粒計數(shù),文中的示例代碼簡潔易懂,具有一定的學(xué)習(xí)價值,需要的小伙伴可以參考下2023-11-11C#實現(xiàn)的文件操作封裝類完整實例【刪除,移動,復(fù)制,重命名】
這篇文章主要介紹了C#實現(xiàn)的文件操作封裝類,結(jié)合完整實例形式分析了C#封裝文件的刪除,移動,復(fù)制,重命名等操作相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2017-03-03C#中字符串優(yōu)化String.Intern、IsInterned詳解
這篇文章主要給大家介紹了關(guān)于C#中字符串優(yōu)化String.Intern、IsInterned的相關(guān)資料,文中通過示例代碼介紹的,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。2017-12-12