zoukankan      html  css  js  c++  java
  • [转]C# 画圆角矩形

    本文转自:http://www.cnblogs.com/xujh/archive/2008/05/12/717433.html

    protected void Page_Load(object sender, EventArgs e)
    {
            Bitmap bm 
    = new Bitmap(800600);
            Graphics g 
    = Graphics.FromImage(bm);
            g.FillRectangle(Brushes.White,
    new Rectangle(0,0,800,600));
            FillRoundRectangle(g,Brushes.Plum,
    new Rectangle(100100100100), 8);
            DrawRoundRectangle(g, Pens.Yellow,
    new Rectangle(100100100100), 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 * 218090);
            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 * 227090);
            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 * 2090);
            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 * 29090);
            roundedRect.AddLine(rect.X, rect.Bottom 
    - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
            roundedRect.CloseFigure();
            
    return roundedRect;
    }
     
  • 相关阅读:
    2008年Web2.0峰会:发展是绝对的硬道理
    盖茨"接班人":微软产品为何总是挨批
    如何使用命令方式检测mx记录是否生效
    IBM公布未来5年将改变人类生活的五大科技
    谷歌李开复:我的传奇人生源于十句箴言
    VCL已死,RAD已死(3)
    VCL已死,RAD已死(2)
    主要程序设计语言范型综论与概要
    谷歌正式放弃与雅虎的广告合作计划
    模仿google分页代码
  • 原文地址:https://www.cnblogs.com/freeliver54/p/1329590.html
Copyright © 2011-2022 走看看