jpfassis

CaptureBackgroundComponente - Delphi

Apr 18th, 2020
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.78 KB | None | 0 0
  1. ///captura o backgroud do componente - somente área do componente
  2. // e passa para um Tbitmap
  3.  
  4. procedure CaptureBackgroundComponente;
  5. var
  6.   canvas: TCanvas;
  7.   dc: HDC;
  8.   sourcerect: TRect;
  9.   FBackground : TBitmap;
  10. begin
  11.   FBackground := TBitmap.Create;
  12.  
  13.   with Fbackground do
  14.   begin
  15.     width := clientwidth;
  16.     height := clientheight;
  17.   end;
  18.  
  19.   sourcerect.TopLeft := ClientToScreen(clientrect.TopLeft);
  20.   sourcerect.BottomRight := ClientToScreen(clientrect.BottomRight);
  21.  
  22.   dc := CreateDC('DISPLAY', nil, nil, nil);
  23.   try
  24.     canvas := TCanvas.Create;
  25.     try
  26.       canvas.handle := dc;
  27.       Fbackground.Canvas.CopyRect(clientrect, canvas, sourcerect);
  28.     finally
  29.       canvas.handle := 0;
  30.       canvas.free;
  31.     end;
  32.   finally
  33.     DeleteDC(dc);
  34.   end;
  35. end;
Add Comment
Please, Sign In to add comment