Solved

TCanvas memory usage and FloodFill

Posted on 2004-04-29
6
818 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
Independent Software Vendors: 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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…

688 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