using System.Drawing; using System.Windows.Forms;namespace ImagePro { public partial class DrawLineFrm : Form { public DrawLineFrm() { InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Point[] points = {new Point(1, 1), new Point(2, 5), new Point(4, 3), new Point(7, 8)}; using (Graphics g = CreateGraphics()) { using (Pen p = new Pen(Color.Black)) { g.DrawLines(p, points); } } } } }可以
用贝兹曲线 private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = this.CreateGraphics(); g.DrawBeziers(new Pen(new SolidBrush(Color.Red)), new Point[] { new Point(10, 10), new Point(20, 50), new Point(40, 30), new Point(70, 80) }); g.Dispose(); }
DrawLines画的是折线图,用贝赛尔曲线绘制的比较平滑的曲线。Graphics g = this.CreateGraphics(); g.DrawBeziers(new Pen(new SolidBrush(Color.Red)), new Point[] { new Point(10, 10), new Point(20, 50), new Point(40, 30), new Point(70, 80) }); g.Dispose();是可以的。
用样条曲线: Point pt1 = new Point(50,50); Point pt2 = new Point(150, 40); Point pt3 = new Point(100, 10); Point pt4= new Point(40, 120); Point pt5 = new Point(160, 130); //绘制样条曲线经过pt1,pt2,pt3,pt4,pt5; g.DrawCurve(bluePen, new Point[] { pt1, pt2, pt3, pt4,pt5 });
using System.Drawing;
using System.Windows.Forms;namespace ImagePro
{
public partial class DrawLineFrm : Form
{
public DrawLineFrm()
{
InitializeComponent();
} protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Point[] points = {new Point(1, 1), new Point(2, 5), new Point(4, 3), new Point(7, 8)};
using (Graphics g = CreateGraphics())
{
using (Pen p = new Pen(Color.Black))
{
g.DrawLines(p, points);
}
}
}
}
}可以
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
g.DrawBeziers(new Pen(new SolidBrush(Color.Red)),
new Point[] { new Point(10, 10), new Point(20, 50), new Point(40, 30), new Point(70, 80) });
g.Dispose();
}
g.DrawBeziers(new Pen(new SolidBrush(Color.Red)),
new Point[] { new Point(10, 10), new Point(20, 50), new Point(40, 30), new Point(70, 80) });
g.Dispose();是可以的。
Point pt1 = new Point(50,50);
Point pt2 = new Point(150, 40);
Point pt3 = new Point(100, 10);
Point pt4= new Point(40, 120);
Point pt5 = new Point(160, 130);
//绘制样条曲线经过pt1,pt2,pt3,pt4,pt5;
g.DrawCurve(bluePen, new Point[] { pt1, pt2, pt3, pt4,pt5 });