在.NET 1.1 里有没有 API里的FloodFill这个东西.
就是怎么像画板颜色填充那样.

解决方案 »

  1.   

    自己写也不难,这是我找到的vb代码,源自http://vb-helper.com/howto_net_unsafe_flood.html
    ' Flood fill the point.
    Public Sub SafeFloodFill(ByVal bm As Bitmap, ByVal x As _
        Integer, ByVal y As Integer, ByVal new_color As Color)
        ' Get the old and new colors.
        Dim old_color As Color = bm.GetPixel(x, y)    ' Start with the original point in the stack.
        Dim pts As New Stack(1000)
        pts.Push(New Point(x, y))
        bm.SetPixel(x, y, new_color)    ' While the stack is not empty, process a point.
        Do While pts.Count > 0
            Dim pt As Point = DirectCast(pts.Pop(), Point)
            If pt.X > 0 Then SafeCheckPoint(bm, pts, pt.X - 1, _
                pt.Y, old_color, new_color)
            If pt.Y > 0 Then SafeCheckPoint(bm, pts, pt.X, pt.Y _
                - 1, old_color, new_color)
            If pt.X < bm.Width - 1 Then SafeCheckPoint(bm, pts, _
                pt.X + 1, pt.Y, old_color, new_color)
            If pt.Y < bm.Height - 1 Then SafeCheckPoint(bm, _
                pts, pt.X, pt.Y + 1, old_color, new_color)
        Loop
    End Sub' See if this point should be added to the stack.
    Private Sub SafeCheckPoint(ByVal bm As Bitmap, ByVal pts As _
        Stack, ByVal x As Integer, ByVal y As Integer, ByVal _
        old_color As Color, ByVal new_color As Color)
        Dim clr As Color = bm.GetPixel(x, y)
        If clr.Equals(old_color) Then
            pts.Push(New Point(x, y))
            bm.SetPixel(x, y, new_color)
        End If
    End Sub