Mastodon
Programmierung

Screen capture

How to capture the desktop screen

[code lang=”delphi”]procedure TForm1.GetDesktopBitmap;
Var
DeskHWnd : Hwnd;
dc: HDC;
ScreenWidth, ScreenHeight: Integer;
TheBmp : TBitmap;
FName : String;
begin
// Get the handle of the Desktop
DeskHWnd := GetDeskTopWindow;
// Get the DeviceContext
dc := GetDC(DeskHWnd);
// Get the screen dimensions
ScreenWidth := GetDeviceCaps(dc,HORZRES);
ScreenHeight := GetDeviceCaps(dc,VERTRES);
// Create the bitmap
TheBmp := TBitmap.Create;
TheBmp.Width := ScreenWidth;
TheBmp.Height := ScreenHeight;
// Lets paint the desktop on the bitmap.
BitBlt(TheBmp.Canvas.Handle, 0,0,ScreenWidth,ScreenHeight,dc, 0,0,SRCCOPY);
// Now we put the bitmap into a TImage
Image1.Picture.Bitmap := TheBmp;
Application.ProcessMessages;
TheBmp.Free;
ReleaseDC(DeskHWnd, dc);
// We need a filename to save it to.
FName := ExtractFilePath(Application.Exename) + ‘capture.bmp’;
// Lets save the bitmap to a file.
Image1.Picture.Bitmap.SaveToFile(FName);
end;
[/code]

[tags]Delphi, Graphic[/tags]

0 Kommentare zu “Screen capture

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.