473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Recursive function works on Windows 2000, but not on Win2003 server

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
Nov 19 '05 #1
6 1506
Hi Martin,

I can't confess to knowing exactly what you're attempting to accomplish, but
have you considered possibily using a loop instead of recursion? 5495
entries on the call stack is quite a few. As far as I can tell you're just
changing the X and Y start positions which I would think could be easily done
with a few nested loops.

You may have a good reason, I just can't see it right off.

"Martin Holmgaard" wrote:
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

Nov 19 '05 #2
Hi Martin,

I can't confess to knowing exactly what you're attempting to accomplish, but
have you considered possibily using a loop instead of recursion? 5495
entries on the call stack is quite a few. As far as I can tell you're just
changing the X and Y start positions which I would think could be easily done
with a few nested loops.

You may have a good reason, I just can't see it right off.

"Martin Holmgaard" wrote:
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

Nov 19 '05 #3
I don't about your win2k3 server error. What I do know is
that .GetPixel() and .SetPixel() are expensive. I "suspect" your
code is probably calling .GetPixel() more often than it really needs
to on quite a few pixels.

I did something "sort of similar" to what you are doing when
evaluating the contents of an image pixel by pixel. Take a
look at this sample and how I went through the image once,
captured the colors for each pixel. Then, used the array
in my evaluation code... You could also test to see if a pixel
has already had .SetPixel() run on it prior to actually calling the method.

http://www.eggheadcafe.com/articles/20031218.asp

--
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.mastervb.net/home/ng/foru...t10017013.aspx
http://www.eggheadcafe.com/articles/..._generator.asp

"Martin Holmgaard" <ma****@holmgaard.com> wrote in message
news:22**************************@posting.google.c om...
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

Nov 19 '05 #4
I don't about your win2k3 server error. What I do know is
that .GetPixel() and .SetPixel() are expensive. I "suspect" your
code is probably calling .GetPixel() more often than it really needs
to on quite a few pixels.

I did something "sort of similar" to what you are doing when
evaluating the contents of an image pixel by pixel. Take a
look at this sample and how I went through the image once,
captured the colors for each pixel. Then, used the array
in my evaluation code... You could also test to see if a pixel
has already had .SetPixel() run on it prior to actually calling the method.

http://www.eggheadcafe.com/articles/20031218.asp

--
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.mastervb.net/home/ng/foru...t10017013.aspx
http://www.eggheadcafe.com/articles/..._generator.asp

"Martin Holmgaard" <ma****@holmgaard.com> wrote in message
news:22**************************@posting.google.c om...
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

Nov 19 '05 #5
Thanks, but it didn't solve my problem. Even if I place the
pixelvalues in 3 arrays, I stille get the error.

For intX = 0 To objBitmap2.Width - 1
For intY = 0 To objBitmap2.Height - 1
pixelR(intX, intY) = objBitmap2.GetPixel(intX, intY).R
pixelG(intX, intY) = objBitmap2.GetPixel(intX, intY).G
pixelB(intX, intY) = objBitmap2.GetPixel(intX, intY).B
Next
Next

Function fncFloodFill(ByVal XStart As Long, ByVal YStart As Long,
ByVal fillColor As Color, ByVal oldColor As Color)
'red = objBitmap2.GetPixel(XStart, YStart).R
'green = objBitmap2.GetPixel(XStart, YStart).G
'blue = objBitmap2.GetPixel(XStart, YStart).B
red = pixelR(XStart, YStart)
green = pixelG(XStart, YStart)
blue = pixelB(XStart, YStart)

If red = oldColor.R Then
If green = oldColor.G Then
If blue = oldColor.B Then
pixelR(XStart, YStart) = fillColor.R
pixelG(XStart, YStart) = fillColor.G
pixelB(XStart, YStart) = fillColor.B
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
End Function
Nov 19 '05 #6
Solved the problem, by using the following FloodFill function in
asp.net C#. Thanks to D. de Haas

/// <summary>
/// ExtGraphics
/// D. de Haas
/// 28 november 2003
/// </summary>

public class ExtGraphics
{
private Bitmap bmp;
private Color bc;

public ExtGraphics(Bitmap b)
{
this.bmp = b;
}

public bool FloodFill(int X, int Y, Color fillColor)
{
if((X < 0) || (X >= bmp.Width) || (Y < 0) || (Y >= bmp.Height))
return false;

bc = bmp.GetPixel(X, Y);
if (bc.ToArgb() == fillColor.ToArgb()) return false;

Stack points = new Stack();

points.Push(new Point(X ,Y));
do
{
Point p = (Point)points.Pop();
bmp.SetPixel(p.X, p.Y, fillColor);

if(this.CanUp(p.X, p.Y)) points.Push(new Point(p.X, p.Y - 1));
if(this.CanRight(p.X, p.Y)) points.Push(new Point(p.X + 1, p.Y));
if(this.CanDown(p.X, p.Y)) points.Push(new Point(p.X, p.Y + 1));
if(this.CanLeft(p.X, p.Y)) points.Push(new Point(p.X - 1, p.Y));
}
while(points.Count > 0);

return true;
}
private bool CanUp(int X, int Y)
{
return((Y > 0) && bmp.GetPixel(X, Y - 1) == bc);
}

private bool CanRight(int X, int Y)
{
return((X < bmp.Width-1) && bmp.GetPixel(X + 1, Y) == bc);
}

private bool CanDown(int X, int Y)
{
return((Y < bmp.Height-1) && bmp.GetPixel(X, Y + 1) == bc);
}

private bool CanLeft(int X, int Y)
{
return((X > 0) && bmp.GetPixel(X - 1, Y) == bc);
}
}
"Robbe Morris [C# MVP]" <in**@turnkeytools.com> wrote in message news:<eC**************@TK2MSFTNGP14.phx.gbl>...
I don't about your win2k3 server error. What I do know is
that .GetPixel() and .SetPixel() are expensive. I "suspect" your
code is probably calling .GetPixel() more often than it really needs
to on quite a few pixels.

I did something "sort of similar" to what you are doing when
evaluating the contents of an image pixel by pixel. Take a
look at this sample and how I went through the image once,
captured the colors for each pixel. Then, used the array
in my evaluation code... You could also test to see if a pixel
has already had .SetPixel() run on it prior to actually calling the method.

http://www.eggheadcafe.com/articles/20031218.asp

--
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.mastervb.net/home/ng/foru...t10017013.aspx
http://www.eggheadcafe.com/articles/..._generator.asp

"Martin Holmgaard" <ma****@holmgaard.com> wrote in message
news:22**************************@posting.google.c om...
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

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Frobinrobin | last post by:
I am running Win2k3 Server and when I try to use the mysql_connect function I am getting an error: Fatal error: Call to undefined function mysql_connect() in...
2
by: Oxmard | last post by:
Armed with my new O'Reilly book Optimizing Oracle Performance I have been trying to get a better understanding of how Oracle works. The book makes the statement, " A database cal with dep=n + 1...
2
by: Patrox | last post by:
Hi ! when installing sqlserver 2000 on a Windows 2003 server it explicitly tells "server not compatible with Windows 2003" during install, but it can carry on. After we applied serfice pack 3a...
1
by: Razarr69 | last post by:
I have a ASP application that I am using for my company and it is currently running on a Windows 2000 server box with IIS 5. The code works perfectly there (except for handling large files - due...
1
by: riless | last post by:
Hi, Is it possible to install on a Windows server 2003, SQL SERVER 2000 in the folowing configuration : SQL server 7.0 as a default Instance and SQL server 2000 as a named instance.
4
by: Rodusa | last post by:
I am having problem to apply updates into this function below. I tried using cursor for updates, etc. but no success. Sql server keeps telling me that I cannot execute insert or update from inside...
2
by: Steven Burn | last post by:
..:: The Specs: MS Access 2000 (host charges extra for SQL/MySQL) MS Windows Server 2003 (prod) / MS XP SP1 (dev) ..:: The setup: The database has been setup with two tables; tblDownloads
0
by: Martin Holmgaard | last post by:
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...
4
by: =?Utf-8?B?ZGlub28=?= | last post by:
We are currently in the process of upgrading our web server from Windows 2000 advanced server to Windows 2003 SP2. We have few ASP.Net applications built with .NET framework 1.1 running on the web...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.