c#中GDI+使用贝塞尔曲线画一朵云
主要是路径的计算
先得到路径
if (value.Width > 0 && value.Height > 0) { GraphicsPath.AddBezier(new PointF(RectangleF.Left + RectangleF.Width * 0.1f, RectangleF.Top + RectangleF.Height * 0.55f), new PointF(RectangleF.Left + RectangleF.Width * 0.1f - RectangleF.Width * 0.05f, RectangleF.Top + RectangleF.Height * 0.55f), new PointF(RectangleF.Left + RectangleF.Width * 0.25f - RectangleF.Width * 0.4f, RectangleF.Top + RectangleF.Height * 0.2f + RectangleF.Height * 0.1f), new PointF(RectangleF.Left + RectangleF.Width * 0.25f, RectangleF.Top + RectangleF.Height * 0.2f)); GraphicsPath.AddBezier(new PointF(RectangleF.Left + RectangleF.Width * 0.25f, RectangleF.Top + RectangleF.Height * 0.2f), new PointF(RectangleF.Left + RectangleF.Width * 0.25f, RectangleF.Top + RectangleF.Height * 0.2f - RectangleF.Height * 0.1f), new PointF(RectangleF.Left + RectangleF.Width * 0.65f - RectangleF.Width * 0.2f, RectangleF.Top + RectangleF.Height * 0.15f - RectangleF.Height * 0.33f), new PointF(RectangleF.Left + RectangleF.Width * 0.65f, RectangleF.Top + RectangleF.Height * 0.15f)); GraphicsPath.AddBezier(new PointF(RectangleF.Left + RectangleF.Width * 0.65f, RectangleF.Top + RectangleF.Height * 0.15f), new PointF(RectangleF.Left + RectangleF.Width * 0.65f + RectangleF.Width * 0.2f, RectangleF.Top + RectangleF.Height * 0.15f - RectangleF.Height * 0.1f), new PointF(RectangleF.Right + RectangleF.Width * 0.1f, RectangleF.Top + RectangleF.Height * 0.45f - RectangleF.Height * 0.25f), new PointF(RectangleF.Right - RectangleF.Width * 0.1f, RectangleF.Top + RectangleF.Height * 0.45f)); GraphicsPath.AddBezier(new PointF(RectangleF.Right - RectangleF.Width * 0.1f, RectangleF.Top + RectangleF.Height * 0.45f), new PointF(RectangleF.Right - RectangleF.Width * 0.1f + RectangleF.Width * 0.15f, RectangleF.Top + RectangleF.Height * 0.45f + RectangleF.Height * 0.1f), new PointF(RectangleF.Right - RectangleF.Width * 0.2f + RectangleF.Width * 0.2f, RectangleF.Bottom - RectangleF.Height * 0.15f), new PointF(RectangleF.Right - RectangleF.Width * 0.2f, RectangleF.Bottom - RectangleF.Height * 0.15f)); GraphicsPath.AddBezier(new PointF(RectangleF.Right - RectangleF.Width * 0.2f, RectangleF.Bottom - RectangleF.Height * 0.15f), new PointF(RectangleF.Right - RectangleF.Width * 0.2f - RectangleF.Width * 0.1f, RectangleF.Bottom + RectangleF.Height * 0.05f), new PointF(RectangleF.Left + RectangleF.Width * 0.3f + RectangleF.Width * 0.1f, RectangleF.Bottom + RectangleF.Height * 0.05f), new PointF(RectangleF.Left + RectangleF.Width * 0.3f, RectangleF.Bottom - RectangleF.Height * 0.15f)); GraphicsPath.AddBezier(new PointF(RectangleF.Left + RectangleF.Width * 0.3f, RectangleF.Bottom - RectangleF.Height * 0.15f), new PointF(RectangleF.Left + RectangleF.Width * 0.3f - RectangleF.Width * 0.2f, RectangleF.Bottom - RectangleF.Height * 0.15f + RectangleF.Height * 0.1f), new PointF(RectangleF.Left + RectangleF.Width * 0.1f - RectangleF.Width * 0.1f, RectangleF.Top + RectangleF.Height * 0.55f + RectangleF.Height * 0.1f), new PointF(RectangleF.Left + RectangleF.Width * 0.1f, RectangleF.Top + RectangleF.Height * 0.55f)); GraphicsPath.CloseAllFigures(); }
得到GraphicsPath就可以绘制了,下面看下效果
作者:冰封一夏
出处:http://www.cnblogs.com/bfyx/
HZHControls官网:http://www.hzhcontrols.cn
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,
且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git