TCanvas memory usage and FloodFill

I designed simply class with TBitmap as main output variable.
1) After drawing function canvas needs to be cleared but if I clear it manualy (by changing colors of pixels) amount of used memory is growing. After many loops it returns exception like "there is no memory to confirm that procedure". I don't know exactly how it translate from polish (very probably that system returns that exception). How can I stop memory from growing?

2) FloodFill is a method from TCanvas and.... it don't work properly or just I can't use this function. I tried several times with other settings but I can't fill one-color square.

----
Sorry for my poor English knowledge.
chudyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_corey_Commented:
Could you post a little of the code around the call to clear the canvas?  perhaps the method if it's small enough.
0
George TokasCommented:
1. Maybe you are trapped in a loop and your function instead of doing what you ask appents data to the bitmap till memory overflow.
2. More info needed to answer.

If you can post some code here 2 see where is the problem.

gtokas.
0
CayceCommented:
Don't use FloodFill to change color of individual pixels. That's why there's a Pixels[int X][int Y] property on TCanvas.

Example 1 (Pulled from my own ....):

// Not that is a good idea to do this, but works!!!
void __fastcall TForm1::someProcedure(TObject* Sender) {
  for(int x = 0; x < 640; x++)
    for(int y = 0; y < 480; y++)
      Canvas->Pixels[x][y] = cBlack;
}

Example 2 (BCB docs):

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  for (int i = 10; i <= 200; i++)
    Canvas->Pixels[i][10] = clRed;
}
0
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

chudyAuthor Commented:
First problem is no longer a trouble for me but I give points to someone who explain me how to use FloodFill or why it don't work properly.

Cayce: I know this method but it is too slow. Can't do this when fps should be no less than 60 and CPU usage with blankscreen no more than 1% on 2ghz CPU. I used rectangle method to draw blank screen but I still need to know how to use FloodFill method.
0
CayceCommented:
TCanvas::FloodFill has two ways of operation:

FloodFill(int X, int Y, TColor Color, TFillStyle FillStyle)

1) fsSurface, replaces one color (the one specified) in a image with a Brush (which can be a simple solid/patterned brush or a 8x8 bitmap brush), starting at the XY coordinates.
2) fsBorder, replaces any color it founds with a Brush, except the specified, starting at XY coordinates.

The brush that is going to be used is the current canvas brush. Canvas->Brush

Let's see, if you have a square of unknown border color, from  0 to 100 with a border of width=2 pixels, filled up with white, and you want to make it red:

Canvas->Brush->Color = clRed;
Canvas->Brush->bsSolid;
Canvas->FloodFill(50, 50, clWhite, fsSurface);

Now you've got another image where you want to replace it's color (unknown) to Red, but you know the Border is Black.

Canvas->Brush->Color = clRed;
Canvas->Brush->bsSolid;
Canvas->FloodFill(50, 50, clBlack, fsBorder);

About the excessive memory usage problem, I think i'll have to see more code to help.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chudyAuthor Commented:
As I say, memory usage problem is no longer a trouble. big thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.