Solved

TCanvas memory usage and FloodFill

Posted on 2004-04-29
6
812 Views
Last Modified: 2013-11-17
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.
0
Comment
Question by:chudy
6 Comments
 
LVL 8

Expert Comment

by:_corey_
ID: 10950809
Could you post a little of the code around the call to clear the canvas?  perhaps the method if it's small enough.
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 10951212
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
 
LVL 9

Expert Comment

by:Cayce
ID: 10954792
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:chudy
ID: 10958686
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
 
LVL 9

Accepted Solution

by:
Cayce earned 200 total points
ID: 10959995
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
 

Author Comment

by:chudy
ID: 10960099
As I say, memory usage problem is no longer a trouble. big thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now