ZKX's LAB

用canvas画只有一个角是圆角的矩形,能画出来么 path画圆角矩形

2021-04-28知识5

用canvas画只有一个角是圆角的矩形,能画出来么 您好,您用用这个方法:float[]radii={12f,12f,0f,0f,0f,0f,0f,0f};path.addRoundRect(new RectF(0,0,50,50),radii,Path.Direction.CW);canvas.drawPath(path,paint);

如何绘制在C#中的圆角矩形 public static GraphicsPath RoundedRect(Rectangle bounds,int radius){int diameter=radius*2;Size size=new Size(diameter,diameter);Rectangle arc=new Rectangle(bounds.Location,size);GraphicsPath path=new GraphicsPath();if(radius=0){path.AddRectangle(bounds);return path;}top left arcpath.AddArc(arc,180,90);top right arcarc.X=bounds.Right-diameter;path.AddArc(arc,270,90);bottom right arcarc.Y=bounds.Bottom-diameter;path.AddArc(arc,0,90);bottom left arcarc.X=bounds.Left;path.AddArc(arc,90,90);path.CloseFigure();return path;}And you can make two extension methods for the Graphics type so youcan use them as the usual Draw.and Fill.shape-drawing methods.public static void DrawRoundedRectangle(this Graphics graphics,Pen pen,Rectangle bounds,int cornerRadius){if(graphics=null)throw new ArgumentNullException(\"graphics\");if(pen=null)throw new ArgumentNullException(\"pen\");using(GraphicsPath path=RoundedRect(bounds,cornerRadius)){graphics.DrawPath(pen,path);}}public static。

怎么用代码写一个圆角矩形? 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);。

#path画圆角矩形

随机阅读

qrcode
访问手机版