473,769 Members | 7,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(By Val XStart As Long, ByVal YStart As Long,
ByVal fillColor As Color, ByVal oldColor As Color)
Dim Red As Long = objBitmap2.GetP ixel(XStart, YStart).R
Dim Green As Long = objBitmap2.GetP ixel(XStart, YStart).G
Dim Blue As Long = objBitmap2.GetP ixel(XStart, YStart).B

If Red = oldColor.R Then
If Green = oldColor.G Then
If Blue = oldColor.B Then
objBitmap2.SetP ixel(XStart, YStart, fillColor)

If XStart + 1 <= objBitmap2.Widt h Then
fncFloodFill(XS tart + 1, YStart, fillColor,
oldColor)
End If

If XStart - 1 >= 0 Then
fncFloodFill(XS tart - 1, YStart, fillColor,
oldColor)
End If

If YStart + 1 <= objBitmap2.Heig ht Then
fncFloodFill(XS tart, YStart + 1, fillColor,
oldColor)
End If

If YStart - 1 >= 0 Then
fncFloodFill(XS tart, YStart - 1, fillColor,
oldColor)
End If
End If
End If
End If
Nov 19 '05 #1
6 1519
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(By Val XStart As Long, ByVal YStart As Long,
ByVal fillColor As Color, ByVal oldColor As Color)
Dim Red As Long = objBitmap2.GetP ixel(XStart, YStart).R
Dim Green As Long = objBitmap2.GetP ixel(XStart, YStart).G
Dim Blue As Long = objBitmap2.GetP ixel(XStart, YStart).B

If Red = oldColor.R Then
If Green = oldColor.G Then
If Blue = oldColor.B Then
objBitmap2.SetP ixel(XStart, YStart, fillColor)

If XStart + 1 <= objBitmap2.Widt h Then
fncFloodFill(XS tart + 1, YStart, fillColor,
oldColor)
End If

If XStart - 1 >= 0 Then
fncFloodFill(XS tart - 1, YStart, fillColor,
oldColor)
End If

If YStart + 1 <= objBitmap2.Heig ht Then
fncFloodFill(XS tart, YStart + 1, fillColor,
oldColor)
End If

If YStart - 1 >= 0 Then
fncFloodFill(XS tart, 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(By Val XStart As Long, ByVal YStart As Long,
ByVal fillColor As Color, ByVal oldColor As Color)
Dim Red As Long = objBitmap2.GetP ixel(XStart, YStart).R
Dim Green As Long = objBitmap2.GetP ixel(XStart, YStart).G
Dim Blue As Long = objBitmap2.GetP ixel(XStart, YStart).B

If Red = oldColor.R Then
If Green = oldColor.G Then
If Blue = oldColor.B Then
objBitmap2.SetP ixel(XStart, YStart, fillColor)

If XStart + 1 <= objBitmap2.Widt h Then
fncFloodFill(XS tart + 1, YStart, fillColor,
oldColor)
End If

If XStart - 1 >= 0 Then
fncFloodFill(XS tart - 1, YStart, fillColor,
oldColor)
End If

If YStart + 1 <= objBitmap2.Heig ht Then
fncFloodFill(XS tart, YStart + 1, fillColor,
oldColor)
End If

If YStart - 1 >= 0 Then
fncFloodFill(XS tart, 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****@holmgaa rd.com> wrote in message
news:22******** *************** ***@posting.goo gle.com...
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(By Val XStart As Long, ByVal YStart As Long,
ByVal fillColor As Color, ByVal oldColor As Color)
Dim Red As Long = objBitmap2.GetP ixel(XStart, YStart).R
Dim Green As Long = objBitmap2.GetP ixel(XStart, YStart).G
Dim Blue As Long = objBitmap2.GetP ixel(XStart, YStart).B

If Red = oldColor.R Then
If Green = oldColor.G Then
If Blue = oldColor.B Then
objBitmap2.SetP ixel(XStart, YStart, fillColor)

If XStart + 1 <= objBitmap2.Widt h Then
fncFloodFill(XS tart + 1, YStart, fillColor,
oldColor)
End If

If XStart - 1 >= 0 Then
fncFloodFill(XS tart - 1, YStart, fillColor,
oldColor)
End If

If YStart + 1 <= objBitmap2.Heig ht Then
fncFloodFill(XS tart, YStart + 1, fillColor,
oldColor)
End If

If YStart - 1 >= 0 Then
fncFloodFill(XS tart, 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****@holmgaa rd.com> wrote in message
news:22******** *************** ***@posting.goo gle.com...
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(By Val XStart As Long, ByVal YStart As Long,
ByVal fillColor As Color, ByVal oldColor As Color)
Dim Red As Long = objBitmap2.GetP ixel(XStart, YStart).R
Dim Green As Long = objBitmap2.GetP ixel(XStart, YStart).G
Dim Blue As Long = objBitmap2.GetP ixel(XStart, YStart).B

If Red = oldColor.R Then
If Green = oldColor.G Then
If Blue = oldColor.B Then
objBitmap2.SetP ixel(XStart, YStart, fillColor)

If XStart + 1 <= objBitmap2.Widt h Then
fncFloodFill(XS tart + 1, YStart, fillColor,
oldColor)
End If

If XStart - 1 >= 0 Then
fncFloodFill(XS tart - 1, YStart, fillColor,
oldColor)
End If

If YStart + 1 <= objBitmap2.Heig ht Then
fncFloodFill(XS tart, YStart + 1, fillColor,
oldColor)
End If

If YStart - 1 >= 0 Then
fncFloodFill(XS tart, 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.Widt h - 1
For intY = 0 To objBitmap2.Heig ht - 1
pixelR(intX, intY) = objBitmap2.GetP ixel(intX, intY).R
pixelG(intX, intY) = objBitmap2.GetP ixel(intX, intY).G
pixelB(intX, intY) = objBitmap2.GetP ixel(intX, intY).B
Next
Next

Function fncFloodFill(By Val XStart As Long, ByVal YStart As Long,
ByVal fillColor As Color, ByVal oldColor As Color)
'red = objBitmap2.GetP ixel(XStart, YStart).R
'green = objBitmap2.GetP ixel(XStart, YStart).G
'blue = objBitmap2.GetP ixel(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.SetP ixel(XStart, YStart, fillColor)

If XStart + 1 <= objBitmap2.Widt h Then
fncFloodFill(XS tart + 1, YStart, fillColor,
oldColor)
End If

If XStart - 1 >= 0 Then
fncFloodFill(XS tart - 1, YStart, fillColor,
oldColor)
End If

If YStart + 1 <= objBitmap2.Heig ht Then
fncFloodFill(XS tart, YStart + 1, fillColor,
oldColor)
End If

If YStart - 1 >= 0 Then
fncFloodFill(XS tart, 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(Bit map 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.ToArg b()) return false;

Stack points = new Stack();

points.Push(new Point(X ,Y));
do
{
Point p = (Point)points.P op();
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.CanRigh t(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.Co unt > 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**@turnkeyto ols.com> wrote in message news:<eC******* *******@TK2MSFT NGP14.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****@holmgaa rd.com> wrote in message
news:22******** *************** ***@posting.goo gle.com...
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(By Val XStart As Long, ByVal YStart As Long,
ByVal fillColor As Color, ByVal oldColor As Color)
Dim Red As Long = objBitmap2.GetP ixel(XStart, YStart).R
Dim Green As Long = objBitmap2.GetP ixel(XStart, YStart).G
Dim Blue As Long = objBitmap2.GetP ixel(XStart, YStart).B

If Red = oldColor.R Then
If Green = oldColor.G Then
If Blue = oldColor.B Then
objBitmap2.SetP ixel(XStart, YStart, fillColor)

If XStart + 1 <= objBitmap2.Widt h Then
fncFloodFill(XS tart + 1, YStart, fillColor,
oldColor)
End If

If XStart - 1 >= 0 Then
fncFloodFill(XS tart - 1, YStart, fillColor,
oldColor)
End If

If YStart + 1 <= objBitmap2.Heig ht Then
fncFloodFill(XS tart, YStart + 1, fillColor,
oldColor)
End If

If YStart - 1 >= 0 Then
fncFloodFill(XS tart, 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
2003
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 C:\Inetpub\wwwroot\programs\index.php on line 8 Now, I def know I've configured my php.ini correctly (its literally the same as my XP machine) and I know that mysql works fine with PHP as I can run it from the command line :D I've got the files (tried in multiple places - but...
2
3428
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 is the recursive child of the first subsequent dep=n database call listed in the SQL data stream. The book gives a few examples, and in trying it out it seemed to work until I tried the following SQL. My question are why does this not keep with...
2
2074
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 then the db server seems to run normally, but does it risk to behave randomly afterwards ??? Is sqlserver 2000 standard edition compatible with Windows 2003 server ? Or does it exist a specific sqlserver edition for Win2003 ?
1
1827
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 to low amount of RAM, I hope anyway - thus the switch to the new server). Now I need to move the application to a better server. My hope was to just copy the folder to the new server and get running. This almost worked. :( The pages seem to...
1
1259
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
9269
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 a function and it gives me an option that I could write an extended stored procedure, but I don't have a clue of how to do it. To quickly fix the problem the only solution left in my case is to convert this recursive function into one recursive...
2
2916
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
817
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 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...
4
2057
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 server. I am looking for the known issues that I need to go over before we start the upgrade. Appreiciate your help.
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3963
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.