Advertisement
jpfassis

CaptureAllScreenToBMP - Delphi in Delphi

Apr 18th, 2020
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.08 KB | None | 0 0
  1. //captura a tela toda e salva em arquivo formato BMP
  2. //CaptureAllScreenToBMP - Delphi
  3.  
  4. procedure CaptureAllScreenToBMP(AFileName: string);
  5. const
  6.   CAPTUREBLT = $40000000;
  7. var
  8.   hdcScreen: HDC;
  9.   hdcCompatible: HDC;
  10.   bmp: TBitmap;
  11.   hbmScreen: HBITMAP;
  12. begin
  13.   // Create a normal DC and a memory DC for the entire screen. The
  14.   // normal DC provides a "snapshot" of the screen contents. The
  15.   // memory DC keeps a copy of this "snapshot" in the associated
  16.   // bitmap.
  17.  
  18.   hdcScreen := CreateDC('DISPLAY', nil, nil, nil);
  19.   hdcCompatible := CreateCompatibleDC(hdcScreen);
  20.   // Create a compatible bitmap for hdcScreen.
  21.  
  22.   hbmScreen := CreateCompatibleBitmap(hdcScreen,
  23.     GetDeviceCaps(hdcScreen, HORZRES),
  24.     GetDeviceCaps(hdcScreen, VERTRES));
  25.  
  26.   // Select the bitmaps into the compatible DC.
  27.   SelectObject(hdcCompatible, hbmScreen);
  28.   bmp := TBitmap.Create;
  29.   bmp.Handle := hbmScreen;
  30.   BitBlt(hdcCompatible,
  31.     0, 0,
  32.     bmp.Width, bmp.Height,
  33.     hdcScreen,
  34.     0, 0,
  35.     SRCCOPY or CAPTUREBLT);
  36.  
  37.   bmp.SaveToFile(AFileName);
  38.   bmp.Free;
  39.   DeleteDC(hdcScreen);
  40.   DeleteDC(hdcCompatible);
  41. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement