标题:颜色填充解决方案
只看楼主
建生65
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2018-5-10
结帖率:100%
 问题点数:0 回复次数:0 
颜色填充解决方案
上一个帖子的解决方案:
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
Dim X0, Y0 As Double
Dim X(1 To 5), Y(1 To 5) As Double
Dim Xtop0, Ytop0, Xbot0, Ybot0 As Double
Private Sub tianchong()
    Dim i As Integer
    Dim Xhalf, Yhalf As Double
    Dim Kx, Ky As Double
    Dim Xpixel(1 To 5), Ypixel(1 To 5) As Double
   
    Picture1.ScaleMode = 3
    Picture1.AutoRedraw = True
    Picture1.ForeColor = vbRed
    Picture1.FillColor = vbBlack
    Picture1.FillStyle = 0
   
    Kx = Picture1.Width / (Xbot0 - Xtop0)
    Ky = Picture1.Height / (Ybot0 - Ytop0)
   
    Xpixel(1) = Kx * X(1): Ypixel(1) = Ky * Y(1)
    Xpixel(2) = Kx * X(2): Ypixel(2) = Ky * Y(2)
    Xpixel(3) = Kx * X(3): Ypixel(3) = Ky * Y(3)
    Xpixel(4) = Kx * X(4): Ypixel(4) = Ky * Y(4)
    Xpixel(5) = Kx * X(5): Ypixel(5) = Ky * Y(5)
   
'    For i = 1 To 5
'        MsgBox Xpixel(i): MsgBox Ypixel(i)
'    Next i
'    MsgBox Picture1.Width: MsgBox Picture1.Height
   
    Picture1.Line (Xpixel(1), Ypixel(1))-(Xpixel(2), Ypixel(2))
    Picture1.Line -(Xpixel(3), Ypixel(3))
    Picture1.Line -(Xpixel(4), Ypixel(4))
    Picture1.Line -(Xpixel(5), Ypixel(5))
    Picture1.Line -(Xpixel(1), Ypixel(1))
'
    X0 = (Xpixel(1) + Xpixel(2) + Xpixel(3) + Xpixel(4) + Xpixel(5)) / 5
    Y0 = (Ypixel(1) + Ypixel(2) + Ypixel(3) + Ypixel(4) + Ypixel(5)) / 5
    MsgBox X0: MsgBox Y0
    Call ExtFloodFill(Picture1.hdc, X0, Y0, vbRed, 0)
   
End Sub

Private Sub Form_Load()
    Xtop0 = 0: Ytop0 = 0
    Xbot0 = 100: Ybot0 = 100
    Form1.ScaleMode = 3
    X(1) = 20: Y(1) = 20
    X(2) = 40: Y(2) = 20
    X(3) = 60: Y(3) = 30
    X(4) = 40: Y(4) = 40
    X(5) = 20: Y(5) = 40
    Call tianchong
    Picture1.Scale (Xtop0, Ytop0)-(Xbot0, Ybot0)
    Picture1.Line (40, 40)-(50, 50), RGB(255, 0, 0)
End Sub

搜索更多相关主题的帖子: Long Dim Double MsgBox Line 
2018-05-17 19:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-487025-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.195703 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved