vB API 之 第八课 图像编程(一)
画线函数
LineTo(): 画直线
PolyBezier() 画贝塞尔曲线
PolyDraw(): 画多边形曲线
Polyline 画线段
LineTo()函数返回Long类型,返回0表示失败,不为0,则成功
参数
hdc: Long //设备的句柄
x和y Long //线段的位置
示例
Option Explicit Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long Dim Flag As Boolean Private Sub Command1_Click() Flag = True End Sub Private Sub Command2_Click() Flag = False End Sub Private Sub Form_Load() Flag = False Me.ScaleMode = 3 Me.Picture1.ScaleMode = 3 End Sub Private 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 Explicit Private Declare Function PolyBezier Lib "gdi32" (ByVal hdc As Long, lppt As POINTAPI, ByVal cPoints As Long) As Long Private Declare Function PolyBezierTo Lib "gdi32" (ByVal hdc As Long, lppt As POINTAPI, ByVal cCount As Long) As Long Private Type POINTAPI X As Long Y As Long End Type Dim flag1 As Boolean Dim flag2 As Boolean Dim pos(10) As POINTAPI Dim i As Integer Private Sub Command1_Click() flag1 = True flag2 = False End Sub Private Sub Command2_Click() flag1 = False flag2 = True End Sub Private Sub Command3_Click() flag1 = False flag2 = False End Sub Private Sub Command4_Click() Me.Picture1.Cls End Sub Private Sub Form_Load() flag1 = False flag2 = False Me.ScaleMode = 3 Me.Picture1.ScaleMode = 3 i = 0 End Sub Private 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