Board index » delphi » Problem drawing on canvas

Problem drawing on canvas

This is a procedure I wrote to draw an explosion bitmap on MainForms canvas.
This routine it called over and over again sometimes with Transparent true
and sometimes with it false. It works for a while but then it crahes and
gives lots of errors saying "Paramater is incorrect" and a couple saing
"Canvas does not allow drawing". The line it seems to crash on is the one
indicated. I have been trying to figure this out for over a week and am
completely stumped, can anyone help?

procedure TMainForm.DrawExplode(ARect:TRect;Transparent:boolean);
var Dest:TRect;
    TempBMp:TBitmap;
begin
     TempBmp:=TBitmap.Create;
     try
         TempBmp.PixelFormat:=pf24Bit;
         TempBmp.Width:=(ARect.Right-ARect.Left)+1;
         TempBmp.Height:=(ARect.Bottom-ARect.Top)+1;
         Dest:=Rect(0,0,TempBmp.Width,TempBmp.Height);
         if Transparent then begin
            TempBmp.Canvas.CopyRect(Dest,Canvas,ARect);
            ExplodeBmp.TransparentColor:=clBlack;
            ExplodeBmp.Transparent:=true;
            TempBmp.Canvas.StretchDraw(Dest,ExplodeBmp); {This is the line
it crashes on}
            Canvas.Draw(ARect.Left,ARect.Top,TempBmp);
            ExplodeBmp.Transparent:=false;
         end
         else begin
            TempBmp.Canvas.StretchDraw(Dest,ExplodeBmp);
            Canvas.Draw(ARect.Left,ARect.Top,TempBmp);
         end
     finally
         TempBmp.Free
     end
end;

Thanks in advance

--Ian Dunn     i...@idunn.in2home.co.uk

 

Re:Problem drawing on canvas


OK, I'm pretty sure the problem is because it gets low in resources. But I
don't have a clue why it gets low in resources. I think I free everthing and
there is only the one window. It's also a bit strange that it fails in that
same drawing routine every time. I do lots of other drawing as well. If
anyone has any idewas that would be a great help

Thanks

Ian Dunn i...@idunn.in2home.co.uk

Quote
In2home User <u...@idunn.in2home.co.uk> wrote in message

news:940769562.8377.0.pink.d4e112c2@news.in2home.co.uk...
Quote
> This is a procedure I wrote to draw an explosion bitmap on MainForms
canvas.
> This routine it called over and over again sometimes with Transparent true
> and sometimes with it false. It works for a while but then it crahes and
> gives lots of errors saying "Paramater is incorrect" and a couple saing
> "Canvas does not allow drawing". The line it seems to crash on is the one
> indicated. I have been trying to figure this out for over a week and am
> completely stumped, can anyone help?

> procedure TMainForm.DrawExplode(ARect:TRect;Transparent:boolean);
> var Dest:TRect;
>     TempBMp:TBitmap;
> begin
>      TempBmp:=TBitmap.Create;
>      try
>          TempBmp.PixelFormat:=pf24Bit;
>          TempBmp.Width:=(ARect.Right-ARect.Left)+1;
>          TempBmp.Height:=(ARect.Bottom-ARect.Top)+1;
>          Dest:=Rect(0,0,TempBmp.Width,TempBmp.Height);
>          if Transparent then begin
>             TempBmp.Canvas.CopyRect(Dest,Canvas,ARect);
>             ExplodeBmp.TransparentColor:=clBlack;
>             ExplodeBmp.Transparent:=true;
>             TempBmp.Canvas.StretchDraw(Dest,ExplodeBmp); {This is the line
> it crashes on}
>             Canvas.Draw(ARect.Left,ARect.Top,TempBmp);
>             ExplodeBmp.Transparent:=false;
>          end
>          else begin
>             TempBmp.Canvas.StretchDraw(Dest,ExplodeBmp);
>             Canvas.Draw(ARect.Left,ARect.Top,TempBmp);
>          end
>      finally
>          TempBmp.Free
>      end
> end;

> Thanks in advance

> --Ian Dunn     i...@idunn.in2home.co.uk

Other Threads