重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
VERSION 5.00 Begin VB.Form FrmMain AutoRedraw = -1 'True Caption = "光滑直线" ClientHeight = 6780 ClientLeft = 60 ClientTop = 450 ClientWidth = 9795 LinkTopic = "Form1" ScaleHeight = 452 ScaleMode = 3 'Pixel ScaleWidth = 653 StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton CmdDraw Caption = "绘制" Height = 375 Left = 120 TabIndex = 0 Top = 120 Width = 1215 End Begin VB.Line Line1 Visible = 0 'False X1 = 48 X2 = 272 Y1 = 128 Y2 = 88 End End Attribute VB_Name = "FrmMain" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long Function Min(s1 As Long, s2 As Long) As Long If s1 s2 Then Min = s1 Else Min = s2 End Function Function Max(s1 As Long, s2 As Long) As Long If s1 s2 Then Max = s1 Else Max = s2 End Function Private Sub CmdDraw_Click() Dim Scal As Single, Gray As Long, MinX As Long, MaxX As Long, MinY As Long, MaxY As Long Dim X1 As Long, X2 As Long, Y1 As Long, Y2 As Long, X3 As Single, Y3 As Single Line1.Visible = False MinX = Min(Line1.X1, Line1.X2): MaxX = Max(Line1.X1, Line1.X2) MinY = Min(Line1.Y1, Line1.Y2): MaxY = Max(Line1.Y1, Line1.Y2) If (Line1.Y1 Line1.Y2 And Line1.X1 Line1.X2) Or (Line1.Y1 Line1.Y2 And Line1.X1 Line1.X2) Then If Abs(Line1.X1 - Line1.X2) Abs(Line1.Y1 - Line1.Y2) Then Scal = Abs(Line1.Y2 - Line1.Y1) / Abs(Line1.X2 - Line1.X1) For i = 0 To MaxX - MinX Y3 = i * Scal + MinY: Y1 = Int(Y3): Y2 = Y1 + 1 Gray = (Y2 - Y3) * 255 SetPixel Me.hdc, i + MinX, Y2, RGB(Gray, Gray, Gray) Gray = (Y3 - Y1) * 255 SetPixel Me.hdc, i + MinX, Y1, RGB(Gray, Gray, Gray) Next i Else Scal = Abs(Line1.X2 - Line1.X1) / Abs(Line1.Y2 - Line1.Y1) For i = 0 To MaxY - MinY X3 = i * Scal + MinX: X1 = Int(X3): X2 = X1 + 1 Gray = (X2 - X3) * 255 SetPixel Me.hdc, X2, i + MinY, RGB(Gray, Gray, Gray) Gray = (X3 - X1) * 255 SetPixel Me.hdc, X1, i + MinY, RGB(Gray, Gray, Gray) Next i End If Else If Abs(Line1.X1 - Line1.X2) Abs(Line1.Y1 - Line1.Y2) Then Scal = -Abs(Line1.Y2 - Line1.Y1) / Abs(Line1.X2 - Line1.X1) For i = 0 To MaxX - MinX Y3 = i * Scal + MaxY: Y1 = Int(Y3): Y2 = Y1 + 1 Gray = (Y2 - Y3) * 255 SetPixel Me.hdc, i + MinX, Y2, RGB(Gray, Gray, Gray) Gray = (Y3 - Y1) * 255 SetPixel Me.hdc, i + MinX, Y1, RGB(Gray, Gray, Gray) Next i Else Scal = -Abs(Line1.X2 - Line1.X1) / Abs(Line1.Y2 - Line1.Y1) For i = 0 To MaxY - MinY X3 = i * Scal + MaxX: X1 = Int(X3): X2 = X1 + 1 Gray = (X2 - X3) * 255 SetPixel Me.hdc, X2, i + MinY, RGB(Gray, Gray, Gray) Gray = (X3 - X1) * 255 SetPixel Me.hdc, X1, i + MinY, RGB(Gray, Gray, Gray) Next i End If End If Me.Refresh End Sub Private Sub Form_Load() Me.ScaleMode = vbPixels Me.AutoRedraw = True End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) Line1.Visible = True Line1.X1 = x: Line1.Y1 = y End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) If Button = vbLeftButton Then Line1.X2 = x: Line1.Y2 = y End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) Line1.X2 = x: Line1.Y2 = y End Sub
公司主营业务:成都网站建设、做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联建站是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联建站推出阿克陶免费做网站回馈大家。
。net 其实还是很好绘制图形的
你可以看下 Graphics 类
Dim d As New Bitmap(Me.Width, Me.Height) ‘一个图片吧
Dim g As Graphics = Graphics.FromImage(d)’绘制 准备在这个图片是进行
然后 就是你绘制的东西了
线 就是 g.DrawLine()
圆 弧度 就用 g.DrawArc(Pens.Black, New Rectangle(0, 0, 400, 200), 0, 360)
复杂的就是 g.DrawBezier()
等 如果你用的是 VS的 编译 上面都有详细的参数说明
Dim d As New Bitmap(Me.Width, Me.Height)
Dim g As Graphics = Graphics.FromImage(d)
g.DrawArc(Pens.Black, New Rectangle(0, 0, 200, 200), 0, 360)
g.DrawLine(Pens.Red, New Point(0, 0), New Point(200, 200))
g.DrawLines(Pens.Green, New Point() {New Point(0, 0), New Point(50, 40), New Point(50, 80), New Point(90, 70), New Point(100, 400)})
g.DrawBezier(Pens.Yellow, New Point(0, 100), New Point(0, 0), New Point(200, 0), New Point(200, 200))
g.Dispose()
Me.BackgroundImage = d
简单说下思路吧,具体的代码可以查资料
首先要会画曲线图,有三种方法:
1、用mschar控件(vb6的);2、用水晶报表;3、用word图表
x轴为时间,y轴为数据
要实现实时数据刷新,只要用 定时器 定时刷新曲线图的数据就可以了(x、y的数据重写)
先分析你的曲线特征,然后选择合适的函数进行拟合。
实现曲线拟合的方法大致可以分为两大类:
1.插值法,给定一组精确的离散数据点,构造一个函数,使其严格依次通过每个数据点,满足光滑的要求。常用的而又多项式插值,抛物样条曲线和三次样条曲线等。
2.逼近法,给定一组具有误差的离散数据点,构造一个函数,使其整体上接近这些数据点,而不必点点通过他们。常用的逼近法有最小二乘法,B样条曲线等
看你的曲线要求选择,找到合适的函数曲线自然就光滑了