文号
t16240
阅读
4933
回复
6
收藏
4
【油漆桶】种子填充算法 (4方向
2009/06/21
IP:广东
输入图像二维数组 直接操作
2  种子坐标
3  宽 高

返回 :

point类型 (可用for循环写入bitmap

Module seed4
    Const FillValue As Integer = 9
    Private backValue As Integer
    Private foreValue As Integer
    Private W As Integer
    Private H As Integer
    Private listCount As Integer
    Private list() As Point

    Public Function startfill(ByVal X As Integer, ByVal Y As Integer, ByVal array(,) As Integer, ByVal myW As Integer, ByVal myH As Integer) As Point()
        If array(X, Y) = 0 Then
            foreValue = 0
            backValue = 1
        Else
            foreValue = 1
            backValue = 0
        End If
        listCount = 0
        W = myW
        H = myH
        ReDim list(listCount)
        fill(X, Y, array)
        Return list
    End Function

    Public Sub fill(ByVal X As Integer, ByVal Y As Integer, ByVal array(,) As Integer)
        array(X, Y) = FillValue
        listCount += 1
        ReDim Preserve list(listCount)
        list(listCount).X = X
        list(listCount).Y = Y

        If Y > 0 Then
            If array(X, Y - 1) = foreValue Then
                fill(X, Y - 1, array)
            End If
        End If
        If X < W Then
            If array(X + 1, Y) = foreValue Then
                fill(X + 1, Y, array)
            End If
        End If
        If Y < H Then
            If array(X, Y + 1) = foreValue Then
                fill(X, Y + 1, array)
            End If
        End If
        If X > 0 Then
            If array(X - 1, Y) = foreValue Then
                fill(X - 1, Y, array)
            End If
        End If
    End Sub
End Module
17年7个月前IP:未同步
112029
1楼
说白了就是画图里的油漆桶或颜料桶的实现方法。各位菜鸟好好学习。
引用
评论
17年7个月前IP:未同步
112167
2楼
是floodfill么?
引用
评论
17年7个月前IP:未同步
112399
3楼
呵呵,典型的递归
什么时候写个回溯的……

那些东西早忘了,考完后再学吧
引用
评论
17年7个月前IP:未同步
112852
4楼
实在没有更快的算法么……
引用
评论
93°作者
17年7个月前IP:未同步
112854
5楼
有啊,人眼法
引用
评论
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的