Solved

TCanvas memory usage and FloodFill

Posted on 2004-04-29
6
810 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_
Comment Utility
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
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:chudy
Comment Utility
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
Comment Utility
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
Comment Utility
As I say, memory usage problem is no longer a trouble. big thanks
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

762 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

9 Experts available now in Live!

Get 1:1 Help Now