Solved

TCanvas memory usage and FloodFill

Posted on 2004-04-29
6
815 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
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.
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 NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

749 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