M
Martin Holmgaard
I have written the following function to be used for flood filling in
a bitmap. The function works fine on Windows XP Prof and Windows 2000
server, but on Windows 2003 server it return a stack overflow if the
function runs recursive more than 5495 times. Does anyone know a
solution on the problem eg. how to extend the stack size on Windows
2003, or better a non-recursive function for flood filling an image ?
Function fncFloodFill(ByVal XStart As Long, ByVal YStart As Long,
ByVal fillColor As Color, ByVal oldColor As Color)
Dim Red As Long = objBitmap2.GetPixel(XStart, YStart).R
Dim Green As Long = objBitmap2.GetPixel(XStart, YStart).G
Dim Blue As Long = objBitmap2.GetPixel(XStart, YStart).B
If Red = oldColor.R Then
If Green = oldColor.G Then
If Blue = oldColor.B Then
objBitmap2.SetPixel(XStart, YStart, fillColor)
If XStart + 1 <= objBitmap2.Width Then
fncFloodFill(XStart + 1, YStart, fillColor,
oldColor)
End If
If XStart - 1 >= 0 Then
fncFloodFill(XStart - 1, YStart, fillColor,
oldColor)
End If
If YStart + 1 <= objBitmap2.Height Then
fncFloodFill(XStart, YStart + 1, fillColor,
oldColor)
End If
If YStart - 1 >= 0 Then
fncFloodFill(XStart, YStart - 1, fillColor,
oldColor)
End If
End If
End If
End If
a bitmap. The function works fine on Windows XP Prof and Windows 2000
server, but on Windows 2003 server it return a stack overflow if the
function runs recursive more than 5495 times. Does anyone know a
solution on the problem eg. how to extend the stack size on Windows
2003, or better a non-recursive function for flood filling an image ?
Function fncFloodFill(ByVal XStart As Long, ByVal YStart As Long,
ByVal fillColor As Color, ByVal oldColor As Color)
Dim Red As Long = objBitmap2.GetPixel(XStart, YStart).R
Dim Green As Long = objBitmap2.GetPixel(XStart, YStart).G
Dim Blue As Long = objBitmap2.GetPixel(XStart, YStart).B
If Red = oldColor.R Then
If Green = oldColor.G Then
If Blue = oldColor.B Then
objBitmap2.SetPixel(XStart, YStart, fillColor)
If XStart + 1 <= objBitmap2.Width Then
fncFloodFill(XStart + 1, YStart, fillColor,
oldColor)
End If
If XStart - 1 >= 0 Then
fncFloodFill(XStart - 1, YStart, fillColor,
oldColor)
End If
If YStart + 1 <= objBitmap2.Height Then
fncFloodFill(XStart, YStart + 1, fillColor,
oldColor)
End If
If YStart - 1 >= 0 Then
fncFloodFill(XStart, YStart - 1, fillColor,
oldColor)
End If
End If
End If
End If