请教如何填充颜色?
用line围成的三角形,怎么填充颜色??
Private Sub FillPic(obj As Object, X As Single, Y As Single, c As Long, Fc As Long) '填充图形,这是一个函数嵌套调用,可填充小面积图形,大面积要多用一个数组再嵌套 On Error Resume Next Dim i As Integer, x1 As Single, y1 As Single, d(3, 1) As Integer For i = 0 To 3: d(i, 0) = 0: d(i, 1) = 0: Next d(0, 0) = -1: d(1, 0) = 1: d(2, 1) = -1: d(3, 1) = 1 '设置步进方向 If obj.Point(X, Y) = c Then obj.PSet (X, Y), Fc For i = 0 To 3 x1 = X + d(i, 0) y1 = Y + d(i, 1) FillPic obj, x1, y1, c, Fc Next End If End Sub Private Sub Form_Load() Me.ScaleMode = 3 Me.AutoRedraw = True Me.Circle (35, 35), 30, vbBlack End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim c As Long If Button = 1 Then c = Me.Point(X, Y) FillPic Me, X, Y, c, vbBlue End If End Sub
Option Explicit Private Declare Function ExtFloodFill Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long, ByVal wFillType As Long) As Long Private Sub Form_Load() Form1.ScaleMode = 3 Picture1.ScaleMode = 3 Picture1.AutoRedraw = True Picture1.ForeColor = vbRed Picture1.FillColor = vbBlue Picture1.FillStyle = 0 Picture1.Line (Picture1.Width / 2, 0)-(0, Picture1.Height) Picture1.Line -(Picture1.Width, Picture1.Height) Picture1.Line -(Picture1.Width / 2, 0) Call ExtFloodFill(Picture1.hdc, Picture1.Width / 2, Picture1.Height / 2, vbRed, 0) End Sub
Option Explicit Private Declare Function ExtFloodFill Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long, ByVal wFillType As Long) As Long Private Sub Form_Load() Form1.ScaleMode = 3 Picture1.ScaleMode = 3 Picture1.AutoRedraw = True Picture1.Circle (Picture1.Width * 0.5, Picture1.Height * 0.5), Picture1.Height * 0.4, vbRed End Sub Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim c As Long, r As Long, g As Long, b As Long, s As Integer Randomize r = Rnd * 255: g = Rnd * 255: b = Rnd * 255 If Button = 1 Then c = Picture1.Point(X, Y) '获取要取代的颜色 Picture1.FillColor = RGB(r, g, b) s = Picture1.FillStyle Picture1.FillStyle = 0 '填充模式 ExtFloodFill Picture1.hdc, X, Y, c, 1 '从鼠标选中的点开始填充随机色(用模式1,模式0是判断边界颜色) Picture1.FillStyle = s '还原填充模式 End If End Sub