Board index » delphi » problem with Brush & FillRect

problem with Brush & FillRect

Hi all!

In my program I do many changes in a TBitmap and display it in a TPaintBox.

Many times in the program I call DecodeRect which does that:

DecodeRect(BGColor: TRGBTriple, Rect: TRect, ImgDest: TBitmap, ...)
begin
    ImgDest.PixelFormat := pf24bit;
    //DRAW THE BG FOR THE RECT
    ImgDest.Canvas.Brush.Color := RGB(BGColor.rgbtRed, BGColor.rgbtGreen,
BGColor.rgbtBlue);
    ImgDest.Canvas.Brush.Style := bsSolid;
    ImgDest.Canvas.FillRect(Rect);
    //DRAW LINES
    //Here, I have a buffer with lines to draw.  I draw these lines with
access by Scanline
   ...

Generally, it works perfectly.  But at a random moment, the background is
not drawn but lines are.  So the lines are just drawn the ones over the
others and it's a real scribble!!!   But no error was raised and if I put a
breakpoint, I can see that BGColor and Rect are ok.

I wonder if the problem is FillRect or the brush??  Did I do the right thing
with Brush and FillRect?  Otherwise, do you have any alternative to suggest
me?

Thanks!!!

Melanie

 

Re:problem with Brush & FillRect


On Tue, 19 Nov 2002 22:01:24 GMT, "hooger"

Quote
<mberge...@NOSPAM.eduglobe.ca> wrote:
>Hi all!

>In my program I do many changes in a TBitmap and display it in a TPaintBox.

>Many times in the program I call DecodeRect which does that:

>DecodeRect(BGColor: TRGBTriple, Rect: TRect, ImgDest: TBitmap, ...)
>begin
>    ImgDest.PixelFormat := pf24bit;
>    //DRAW THE BG FOR THE RECT
>    ImgDest.Canvas.Brush.Color := RGB(BGColor.rgbtRed, BGColor.rgbtGreen,
>BGColor.rgbtBlue);
>    ImgDest.Canvas.Brush.Style := bsSolid;
>    ImgDest.Canvas.FillRect(Rect);
>    //DRAW LINES
>    //Here, I have a buffer with lines to draw.  I draw these lines with
>access by Scanline
>   ...

>Generally, it works perfectly.  But at a random moment, the background is
>not drawn but lines are.  So the lines are just drawn the ones over the
>others and it's a real scribble!!!   But no error was raised and if I put a
>breakpoint, I can see that BGColor and Rect are ok.

>I wonder if the problem is FillRect or the brush??  Did I do the right thing
>with Brush and FillRect?  Otherwise, do you have any alternative to suggest
>me?

Are you doing anything in the form's Paint event that changes a TImage
(rather than the TPaintBox, which is safe)?

Any changes in a TImage cause it to refresh itself, causing the form
to get a WM_PAINT messgage, so the Paint event gets run continuously.
A symptom of this is often flickering lines on the TImage...

--
jc

Re:problem with Brush & FillRect


Maybe if you used LockWindowUpdate ...

Is there any pattern to the times that the background is not blanked ?

Perhaps when the mouse moves over the control, or when it is being
moved.

On Tue, 19 Nov 2002 22:01:24 GMT, "hooger"

Quote
<mberge...@NOSPAM.eduglobe.ca> wrote:
>Hi all!

>In my program I do many changes in a TBitmap and display it in a TPaintBox.

>Many times in the program I call DecodeRect which does that:

>DecodeRect(BGColor: TRGBTriple, Rect: TRect, ImgDest: TBitmap, ...)
>begin
>    ImgDest.PixelFormat := pf24bit;
>    //DRAW THE BG FOR THE RECT
>    ImgDest.Canvas.Brush.Color := RGB(BGColor.rgbtRed, BGColor.rgbtGreen,
>BGColor.rgbtBlue);
>    ImgDest.Canvas.Brush.Style := bsSolid;
>    ImgDest.Canvas.FillRect(Rect);
>    //DRAW LINES
>    //Here, I have a buffer with lines to draw.  I draw these lines with
>access by Scanline
>   ...

>Generally, it works perfectly.  But at a random moment, the background is
>not drawn but lines are.  So the lines are just drawn the ones over the
>others and it's a real scribble!!!   But no error was raised and if I put a
>breakpoint, I can see that BGColor and Rect are ok.

>I wonder if the problem is FillRect or the brush??  Did I do the right thing
>with Brush and FillRect?  Otherwise, do you have any alternative to suggest
>me?

>Thanks!!!

>Melanie

Re:problem with Brush & FillRect


Here's some details :

At first, I write into a TBitmap and after, I update it to the TPaintBox.  I don't use TImage because, as you said Jeremy, it makes flickering lines on image and with a TPaintBox I don't have this problem.  Too, I noticed that the problem is not only at the level of the TPaintBox, it's the Bitmap that is not ok and I draw the bitmap on the TPaintBox, so I see that the problem comes from the bitmap.  I don't notice any pattern to the times that the background is not blanked, but once it occur, I can't draw any background without restarting the program.  It's like if a TBrush or anything were not available anymore.  Is it possible??

Thanks!!!

Melanie

Quote
"hooger" <mberge...@NOSPAM.eduglobe.ca> wrote in message news:UwyC9.852$Zp1.78531@charlie.risq.qc.ca...
> Hi all!

> In my program I do many changes in a TBitmap and display it in a TPaintBox.

> Many times in the program I call DecodeRect which does that:

> DecodeRect(BGColor: TRGBTriple, Rect: TRect, ImgDest: TBitmap, ...)
> begin
>     ImgDest.PixelFormat := pf24bit;
>     //DRAW THE BG FOR THE RECT
>     ImgDest.Canvas.Brush.Color := RGB(BGColor.rgbtRed, BGColor.rgbtGreen,
> BGColor.rgbtBlue);
>     ImgDest.Canvas.Brush.Style := bsSolid;
>     ImgDest.Canvas.FillRect(Rect);
>     //DRAW LINES
>     //Here, I have a buffer with lines to draw.  I draw these lines with
> access by Scanline
>    ...

> Generally, it works perfectly.  But at a random moment, the background is
> not drawn but lines are.  So the lines are just drawn the ones over the
> others and it's a real scribble!!!   But no error was raised and if I put a
> breakpoint, I can see that BGColor and Rect are ok.

> I wonder if the problem is FillRect or the brush??  Did I do the right thing
> with Brush and FillRect?  Otherwise, do you have any alternative to suggest
> me?

> Thanks!!!

> Melanie

Re:problem with Brush & FillRect


On Wed, 20 Nov 2002 13:46:15 GMT, "hooger"

Quote
<mberge...@NOSPAM.eduglobe.ca> wrote:
>Here's some details :

>At first, I write into a TBitmap and after, I update it to the TPaintBox.  I don't use TImage because,
>as you said Jeremy, it makes flickering lines on image and with a TPaintBox I don't have this problem.  
>Too, I noticed that the problem is not only at the level of the TPaintBox, it's the Bitmap that is not ok
>and I draw the bitmap on the TPaintBox, so I see that the problem comes from the bitmap.  I don't
>notice any pattern to the times that the background is not blanked, but once it occur, I can't draw any
>background without restarting the program.  It's like if a TBrush or anything were not available anymore.
>Is it possible??

I can't think of anything besides running out of memory which would
cause FillRect to stop working, so I guess you're right in suspecting
the brush.

It's certainly possible to free a TBrush, but if you were doing this
(even accidentally) I suspect you'd be getting access violations.

Are there any calls to ReleaseDC or DeleteDC in your code which might
be messing with the canvas? Is the brush style being set to something
other than bsSolid somehow?  Are you making an assignment to
Brush.Handle somewhere, setting it to an invalid HBRUSH?

Perhaps you've got a "with Brush do begin... end;" somewhere, and
there's a line of code in there that's doing something unexpected to
the brush?

Maybe if you start a test project, and just copy across the code for
this painting operation it'll help track down the bug.

--
jc

Re:problem with Brush & FillRect


In fact, the only place where I used a TBrush is in the DecodeRect function at these lines :

ImgDest.Canvas.Brush.Color := RGB(BGColor.rgbtRed, BGColor.rgbtGreen,
BGColor.rgbtBlue);
ImgDest.Canvas.Brush.Style := bsSolid;

Too, I don't use ReleaseDC or DeleteDC in my code.  

If I start a test project which do Encode & Decode, I never got background problem.

So, I think that I run out of ressources elsewhere in my code and, in consequence, I got no bakground with DecodeRects.

To resolve the problem, until I find the OutOfRessources problem, do I have to stop using TBrush?

Thanks,

Melanie

Quote
"Jeremy Collins" <jd.coll...@ntlworld.com> wrote in message news:v85ntu49k3mkrbdd5l6i7uqgv87nfnsipr@4ax.com...
> On Wed, 20 Nov 2002 13:46:15 GMT, "hooger"
> <mberge...@NOSPAM.eduglobe.ca> wrote:

> >Here's some details :

> >At first, I write into a TBitmap and after, I update it to the TPaintBox.  I don't use TImage because,
> >as you said Jeremy, it makes flickering lines on image and with a TPaintBox I don't have this problem.  
> >Too, I noticed that the problem is not only at the level of the TPaintBox, it's the Bitmap that is not ok
> >and I draw the bitmap on the TPaintBox, so I see that the problem comes from the bitmap.  I don't
> >notice any pattern to the times that the background is not blanked, but once it occur, I can't draw any
> >background without restarting the program.  It's like if a TBrush or anything were not available anymore.
> >Is it possible??

> I can't think of anything besides running out of memory which would
> cause FillRect to stop working, so I guess you're right in suspecting
> the brush.

> It's certainly possible to free a TBrush, but if you were doing this
> (even accidentally) I suspect you'd be getting access violations.

> Are there any calls to ReleaseDC or DeleteDC in your code which might
> be messing with the canvas? Is the brush style being set to something
> other than bsSolid somehow?  Are you making an assignment to
> Brush.Handle somewhere, setting it to an invalid HBRUSH?

> Perhaps you've got a "with Brush do begin... end;" somewhere, and
> there's a line of code in there that's doing something unexpected to
> the brush?

> Maybe if you start a test project, and just copy across the code for
> this painting operation it'll help track down the bug.

> --
> jc

Re:problem with Brush & FillRect


On Thu, 21 Nov 2002 13:26:38 GMT, "hooger"

Quote
<mberge...@NOSPAM.eduglobe.ca> wrote:
>In fact, the only place where I used a TBrush is in the DecodeRect function at these lines :

>ImgDest.Canvas.Brush.Color := RGB(BGColor.rgbtRed, BGColor.rgbtGreen,
>BGColor.rgbtBlue);
>ImgDest.Canvas.Brush.Style := bsSolid;

>Too, I don't use ReleaseDC or DeleteDC in my code.  

>If I start a test project which do Encode & Decode, I never got background problem.

>So, I think that I run out of ressources elsewhere in my code and, in consequence, I got no bakground with DecodeRects.

>To resolve the problem, until I find the OutOfRessources problem, do I have to stop using TBrush?

Well, I can't see any problem with your use of TBrush here, so there's
no harm in continuing to use it.  If your test project worked OK, then
the error must be in another block of code. All I can suggest is that
you keep adding code from your main project to the test project,
function by function until the problem occurs (alternativley make a
copy of the main project and keep removing chunks of code until the
error goes away).

Once you've narrowed down where the bug is, you'll probably be able to
see what's wrong, if not post the offending block of code here.
--
jc

Re:problem with Brush & FillRect


"Jeremy Collins" <jd.coll...@ntlworld.com> skrev i melding
news:dkqptucrabhgjcft1o0jsfji67m1vhdjsk@4ax.com...
Quote
> On Thu, 21 Nov 2002 13:26:38 GMT, "hooger"
> <mberge...@NOSPAM.eduglobe.ca> wrote:

> >In fact, the only place where I used a TBrush is in the DecodeRect

function at these lines :
Quote

> >ImgDest.Canvas.Brush.Color := RGB(BGColor.rgbtRed, BGColor.rgbtGreen,
> >BGColor.rgbtBlue);
> >ImgDest.Canvas.Brush.Style := bsSolid;

> >Too, I don't use ReleaseDC or DeleteDC in my code.

> >If I start a test project which do Encode & Decode, I never got
background problem.

> >So, I think that I run out of ressources elsewhere in my code and, in

consequence, I got no bakground with DecodeRects.
Quote

> >To resolve the problem, until I find the OutOfRessources problem, do I

have to stop using TBrush?

Quote

> Well, I can't see any problem with your use of TBrush here, so there's
> no harm in continuing to use it.  If your test project worked OK, then
> the error must be in another block of code. All I can suggest is that
> you keep adding code from your main project to the test project,
> function by function until the problem occurs (alternativley make a
> copy of the main project and keep removing chunks of code until the
> error goes away).

> Once you've narrowed down where the bug is, you'll probably be able to
> see what's wrong, if not post the offending block of code here.

This has to be Win98/ME, right ? Run "Resource Meter", check for available
GDI resources. Whenever you're dropping below 50%, there may be a problem
with updates. Delphi eats a *lot* of GDI resources, running in IDE may
actually be out of the question for more than a few times immediately after
booting the machine.

--
Bj?rge S?ther
bjorge@hahaha_itte.no

Re:problem with Brush & FillRect


I found an error in my code that cause OutOfRessources.  Since it was resolved, I didn't have the background problem anymore.  So, I conclude that the background problem was the result of that.  

Thanks to you all for your help!!

Melanie

  "hooger" <mberge...@NOSPAM.eduglobe.ca> wrote in message news:HmMC9.3336$Zp1.110190@charlie.risq.qc.ca...
  Here's some details :

  At first, I write into a TBitmap and after, I update it to the TPaintBox.  I don't use TImage because, as you said Jeremy, it makes flickering lines on image and with a TPaintBox I don't have this problem.  Too, I noticed that the problem is not only at the level of the TPaintBox, it's the Bitmap that is not ok and I draw the bitmap on the TPaintBox, so I see that the problem comes from the bitmap.  I don't notice any pattern to the times that the background is not blanked, but once it occur, I can't draw any background without restarting the program.  It's like if a TBrush or anything were not available anymore.  Is it possible??

  Thanks!!!

  Melanie

  "hooger" <mberge...@NOSPAM.eduglobe.ca> wrote in message news:UwyC9.852$Zp1.78531@charlie.risq.qc.ca...
  > Hi all!
  >
  > In my program I do many changes in a TBitmap and display it in a TPaintBox.
  >
  > Many times in the program I call DecodeRect which does that:
  >
  > DecodeRect(BGColor: TRGBTriple, Rect: TRect, ImgDest: TBitmap, ...)
  > begin
  >     ImgDest.PixelFormat := pf24bit;
  >     //DRAW THE BG FOR THE RECT
  >     ImgDest.Canvas.Brush.Color := RGB(BGColor.rgbtRed, BGColor.rgbtGreen,
  > BGColor.rgbtBlue);
  >     ImgDest.Canvas.Brush.Style := bsSolid;
  >     ImgDest.Canvas.FillRect(Rect);
  >     //DRAW LINES
  >     //Here, I have a buffer with lines to draw.  I draw these lines with
  > access by Scanline
  >    ...
  >
  > Generally, it works perfectly.  But at a random moment, the background is
  > not drawn but lines are.  So the lines are just drawn the ones over the
  > others and it's a real scribble!!!   But no error was raised and if I put a
  > breakpoint, I can see that BGColor and Rect are ok.
  >
  > I wonder if the problem is FillRect or the brush??  Did I do the right thing
  > with Brush and FillRect?  Otherwise, do you have any alternative to suggest
  > me?
  >
  > Thanks!!!
  >
  >
  > Melanie
  >
  >

Other Threads