首页 > 代码库 > vB API 之 第八课 图像编程(一)

vB API 之 第八课 图像编程(一)

  画线函数

  LineTo(): 画直线

  PolyBezier() 画贝塞尔曲线

  PolyDraw(): 画多边形曲线

  Polyline 画线段

  LineTo()函数返回Long类型,返回0表示失败,不为0,则成功

  参数

  hdc: Long  //设备的句柄

  x和y  Long   //线段的位置

示例 

Option ExplicitPrivate Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As LongDim Flag As BooleanPrivate Sub Command1_Click()    Flag = True    End SubPrivate Sub Command2_Click()    Flag = False    End SubPrivate Sub Form_Load()    Flag = False    Me.ScaleMode = 3    Me.Picture1.ScaleMode = 3End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)    If Flag Then        LineTo Me.Picture1.hdc, X, Y    End If    End Sub

PolyBezier()、PolyBezierTo()函数描绘一条或多条贝塞尔曲线。

参数

  hdc: long    //设备的句柄

  lppt: POINTAPI结构,其中第一点指定了起点,其余三点为一组,指定控制一条曲线形状。

  CPoints: Long   // lppt数组的总数

  POINTAPI结构如下

Private Type POINTAPI     x As Long     y As Long End Type 

示例 绘制贝塞尔曲线

Option ExplicitPrivate Declare Function PolyBezier Lib "gdi32" (ByVal hdc As Long, lppt As POINTAPI, ByVal cPoints As Long) As LongPrivate Declare Function PolyBezierTo Lib "gdi32" (ByVal hdc As Long, lppt As POINTAPI, ByVal cCount As Long) As LongPrivate Type POINTAPI    X As Long    Y As LongEnd TypeDim flag1 As BooleanDim flag2 As BooleanDim pos(10) As POINTAPIDim i As IntegerPrivate Sub Command1_Click()    flag1 = True    flag2 = False    End SubPrivate Sub Command2_Click()    flag1 = False    flag2 = True    End SubPrivate Sub Command3_Click()    flag1 = False    flag2 = FalseEnd SubPrivate Sub Command4_Click()    Me.Picture1.Cls    End SubPrivate Sub Form_Load()    flag1 = False    flag2 = False    Me.ScaleMode = 3    Me.Picture1.ScaleMode = 3    i = 0End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)    If flag1 Then        pos(i).X = X        pos(i).Y = Y        If (i >= 3) Then            PolyBezier Me.Picture1.hdc, pos(0), 4            Me.Picture1.Circle (X, Y), 3            i = 0            Exit Sub        End If    End If    If flag2 Then        pos(i).X = X        pos(i).Y = Y        If (i >= 3) Then            PolyBezierTo Me.Picture1.hdc, pos(0), 3            Me.Picture1.Circle (X, Y), 3            i = 0            Exit Sub        End If    End If    If (i <= 3) Then        i = i + 1        Me.Picture1.Circle (X, Y), 3    End If            End Sub

 

vB API 之 第八课 图像编程(一)