i got this floodfill code from the internet, but its too slow.
does anyone know of a faster way to floodfill an area?Code:Public Sub FloodFill(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(100) 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 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




Reply With Quote