VB6.0 我利用点画如下图形,能够用各点画出各条线,但是由于是用一条一条线画的,怎样给如下部分填充颜色
2个回答
展开全部
嗯,这个问题挺好,有一定普遍性。这个虽然也可以通过纯VB支持函数解决,但效率太低,代码复杂,没有采用的意义。通常都是通过调用API函数来解决的。常见方法有两种。
1、用路径解决。参考:https://msdn.microsoft.com/en-us/library/dd162782%28v=vs.85%29.aspx
Private Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function AngleArc Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal dwRadius As Long, ByVal eStartAngle As Single, ByVal eSweepAngle As Single) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpPoint As Long) As Long
Private Declare Function FillPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function StrokePath Lib "gdi32" (ByVal hdc As Long) As Long
你可以在VB6中声明需要用到的API函数,先Begin,画,再End,Stroke,Fill。这样画出的图形不受颜色限制,形状可控可靠。
2、用填充解决。下面是一个简单的例子。
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
用这种方法解决你的问题需要指定待填充的区域边缘颜色,也就是说要事先用相同颜色画好边线,然后用模式0来填充。
展开全部
可以使用pset去填充颜色。
更多追问追答
追问
那就是直接画点咯?要怎么画好呢,能给举个例子吗
追答
Picture1.Cls '清空Picture1中的图像显示
Dim T As Integer '定义一个临时变量
'以下循环是将读取到的原图像的数据显示到Pciture1中
For i = 0 To 255
For j = 0 To 255
Picture1.PSet (i, j), RGB(PicIniT(i, j), PicIniT(i, j), PicIniT(i, j))
Next j
Next i
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询