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),
;
DrawRoundRectangle(g, Pens.Yellow,new Rectangle(100, 100, 100, 100),
;
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#画圆角矩形的方法,涉及C#绘图的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
渐变背景色窗体以及渐变背景色的圆角矩形Label
重写pictureBox相关事件,支持在pictureBox上绘制多矩形框 ,以及选中绘制框,选中后支持边框拉伸。
C# GDI 阴影 圆角矩形 源代码 可用VS打开。
自己写的圆角矩形控件,显示内容可以随意更换,实现数据可视化
圆角矩形按钮图形草案,画出来的,没加事件. 背景色,边线,颜色有枚举
圆角矩形窗体
小米logo换新,程序员一行代码(border-radius:19px)实现,目前此行代码价值200万。C#/wpf实现
只包含 一个返回圆角矩形路劲的方法 和 一个枚举 (里面包含 各种方向的圆角) 看着参数就会用啦
Android开发摄像头SurfaceView预览 背景画图(矩形和圆形) 实现(双surfaceview,顶层画矩形框,底层预览视频); UI:三个按钮 预览 摄像 图片保存,预览界面 可以显示(矩形和圆形等图画)
模仿360,毒霸悟空等界面,重绘C#窗体。注意,如果窗体中有Thread线程睡眠操作,要添加Applection.DoEvent()方法。
使用C#实现窗体的圆角。对于矩形的窗体,要在一个角上画个弧度至少需要2个点,所以4个角需要至少8个点
1、圆角枚举与相应组合处理设计 2、GraphicsPath.AddArc方法 3、绘制圆角组合 从以上几点详细论述如何实现绘制矩形圆角
通过GDI+编程,将定义的矩形类绘制到窗口上,并通过鼠标操作实现矩形的进入变色、拖拽移动、右键菜单等功能。
C# GDI Draw画圆画矩形,绘制几何图形,创建Graphics对象,向用户显示控件, 创建蓝色画笔画矩形,创建红色画笔画椭圆,把窗口背景色设为白色,以便清楚的看到所绘制的图形。 运行环境:Visual Studio2010
C# 简单地在WinForm上放置一个有阴影边框的矩形面板C# 简单地在WinForm上放置一个有阴影边框的矩形面板C# 简单地在WinForm上放置一个有阴影边框的矩形面板C# 简单地在WinForm上放置一个有阴影边框的矩形面板C# 简单...
我用的是c#2008编写的程序,里面包含的功能有橡皮擦,取色,铅笔,直线,矩形,椭圆,圆角矩形功能。
C# 高仿 Windows 画图板,实现图片的打开/保存/文字绘制/矩形/圆形/椭圆形/圆角矩形/画刷/画笔/喷枪/曲线/取色等功能。
C# 高仿 Windows 画图板,实现图片的打开/保存/文字绘制/矩形/圆形/椭圆形/圆角矩形/画刷/画笔/喷枪/曲线/取色等功能。