Board index » delphi » BitBlt doesn't get updated on canvas

BitBlt doesn't get updated on canvas

I'm BitBlting images onto the canvas of a form.  That works great.  Now I
need to BitBlt onto the canvas of any other type of component that has a
canvas property.  The problem is that when BitBlting to a canvas on a
component (TImage for example), It does not get updated until I issue a
(WhatEverComponent).canvas.refresh.

What I'm hoping for is some (incredibly fast) way to force only a small
rectangle on the canvas to get repainted.  I've searched through the TCanvas
VCL info and through the WinAPI but can't find anything that seems to do
that.  I have attempted the following:  Image.refresh repaints the entire
bitmap image.... Way too slow when all I'm doing is animating a small sprite
on a full screen bitmap.

//=============================
      DirtyRect.left:=x;
      DirtyRect.top:=y;
      DirtyRect.right:=x+150;     //sprite is 150x150
      DirtyRect.bottom:=y+150;
      InvalidateRect(Image1.picture.bitmap.canvas.handle,
                     @DirtyRect, false {Don't erase background});
      PostMessage(Image1.picture.handle,WM_Paint,0,0);
//=============================

Which does nothing for some reason.

 

Re:BitBlt doesn't get updated on canvas


I use InvalidateRect (or InvalidateRgn) followed by MyPaintBox.Update.
This works just fine for me. I do not have my source code or Delphi here
so a) I can't promise TImage has the Update method (but strongly suspect
that it does and b) I can't promise this is what I do <g>. The key for
you though should be the Update method. It is helpful to compare the
Help on the Refresh, Invalidate and Update methods.

Quote
Michael J. Quinn wrote:

> I'm BitBlting images onto the canvas of a form.  That works great.  Now I
> need to BitBlt onto the canvas of any other type of component that has a
> canvas property.  The problem is that when BitBlting to a canvas on a
> component (TImage for example), It does not get updated until I issue a
> (WhatEverComponent).canvas.refresh.

> What I'm hoping for is some (incredibly fast) way to force only a small
> rectangle on the canvas to get repainted.  I've searched through the TCanvas
> VCL info and through the WinAPI but can't find anything that seems to do
> that.  I have attempted the following:  Image.refresh repaints the entire
> bitmap image.... Way too slow when all I'm doing is animating a small sprite
> on a full screen bitmap.

> //=============================
>       DirtyRect.left:=x;
>       DirtyRect.top:=y;
>       DirtyRect.right:=x+150;     //sprite is 150x150
>       DirtyRect.bottom:=y+150;
>       InvalidateRect(Image1.picture.bitmap.canvas.handle,
>                      @DirtyRect, false {Don't erase background});
>       PostMessage(Image1.picture.handle,WM_Paint,0,0);
> //=============================

> Which does nothing for some reason.

Other Threads