GDI+最适合绘制直角类型的图形,但您可以使用它来产生这样的效果:
alt text http://img7.imageshack.us/img7/3497/crudite.jpg
…通过使用
拉丝贝齐尔
图形对象的方法。下面是呈现上述图像的代码段:
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
g.FillRectangle(new SolidBrush(Color.White),
new Rectangle(0, 0, bmp.Width, bmp.Height));
Pen pen = new Pen(Color.Gray, 7.0F);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.DrawBezier(pen,
new Point(10, 10),
new Point(11, 41),
new Point(7, 147),
new Point(13, 199));
g.DrawBezier(pen,
new Point(7, 10),
new Point(87, 13),
new Point(213, 17),
new Point(319, 6));
g.DrawBezier(pen,
new Point(319, 4),
new Point(305, 53),
new Point(299, 107),
new Point(319, 203));
g.DrawBezier(pen,
new Point(13, 199),
new Point(33, 195),
new Point(150, 207),
new Point(319, 203));
}
pictureBox1.Image = bmp;
这种效果的关键是使用一个大宽度的笔(本例中为7.0f),并将图形对象的平滑模式设置为高质量(因为在默认平滑模式下,这看起来像屁股)。
编写自定义方法比较容易,在这些方法中,您指定要以常规gdi+方式绘制的形状(矩形、坐标和半径等),然后您的代码将这些元素的行转换为贝塞尔坐标,在贝塞尔坐标中,您可以在每个方向上以几个像素随机改变事物的位置。