Board index » delphi » How to copy from canvas to tbitmap.canvas

How to copy from canvas to tbitmap.canvas

"leapin" <wa...@resa.net> schrieb im Newsbeitrag news:3c55ac9a$1_1@dnews...

Quote
> var map : TBitMap;
> Form1.OnDeactivate;
> Begin
>    Form1.Canvas := map.canvas;
> {I've tried several methos with no success}
> End;

> This gives me that form1.Canvas is read only;

> I want to save my picture on the forms Deactivate. (fastest file, stream?)
> I want to load my picture on the forms Activate.
> Any sample code would be awsome.
> Thanks

Take a look at the following code

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  var bmp : TBitmap;
begin
  bmp := TBitmap.Create;
    bmp.Width := Width;
    bmp.Height := Height;

    //Copys the Forms Canvas into the Bitmaps Canvas
    BitBlt( bmp.Canvas.Handle,
            0, 0, Width, Height,
            Canvas.Handle,
            0, 0, SRCCOPY );

    bmp.SaveToFile( 'C:\FormClose.bmp');
  bmp.Free;
end;

Christian

 

Re:How to copy from canvas to tbitmap.canvas


var map : TBitMap;
Form1.OnDeactivate;
Begin
   Form1.Canvas := map.canvas;
{I've tried several methos with no success}
End;

This gives me that form1.Canvas is read only;

I want to save my picture on the forms Deactivate. (fastest file, stream?)
I want to load my picture on the forms Activate.
Any sample code would be awsome.
Thanks

Re:How to copy from canvas to tbitmap.canvas


Quote
"Christian Schneider" <cw...@pgcenter.de> wrote in message <news:3c55ae80_2@dnews>...
> "leapin" <wa...@resa.net> schrieb im Newsbeitrag news:3c55ac9a$1_1@dnews...
> > var map : TBitMap;
> > Form1.OnDeactivate;
> > Begin
> >    Form1.Canvas := map.canvas;
> > {I've tried several methos with no success}
> > End;

> > This gives me that form1.Canvas is read only;

> > I want to save my picture on the forms Deactivate. (fastest file, stream?)
> > I want to load my picture on the forms Activate.
> > Any sample code would be awsome.
> > Thanks

> Take a look at the following code

> procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
>   var bmp : TBitmap;
> begin
>   bmp := TBitmap.Create;
>     bmp.Width := Width;
>     bmp.Height := Height;

>     //Copys the Forms Canvas into the Bitmaps Canvas
>     BitBlt( bmp.Canvas.Handle,
>             0, 0, Width, Height,
>             Canvas.Handle,
>             0, 0, SRCCOPY );

>     bmp.SaveToFile( 'C:\FormClose.bmp');
>   bmp.Free;
> end;

> Christian

Form canvases loose their info if you drag them off the screen or
cover them up.

Timage.canvases don't, and they have a method to save as a bitmap.  I
don't know if that's a better way or not, just fyi.

Other Threads