DelphiFAQ Home Search:
General :: Windows :: Programming :: Windows with Delphi :: Windows Graphics
Graphics programming under Windows with Delphi.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Screen capture into a BMP file

You need to make a screenshot from your application? This little routine grabs the whole screen, assigns it temporary to a bitmap and stores it into file "sample.bmp".

A potential problem:
If your system is set up to HiColor (32k colors = 15 bits per pixel), some programs will not be able to read the result since they are only capable to read 16 bits/ pixel.

procedure TForm1.Button1Click(Sender: TObject);
 var
   DeskTopDC: HDc;
   DeskTopCanvas: TCanvas;
   DeskTopRect: TRect;
   Bitmap: TBitmap;
 begin
   DeskTopDC := GetWindowDC(GetDeskTopWindow);
   DeskTopCanvas := TCanvas.Create;
   DeskTopCanvas.Handle := DeskTopDC;
   DeskTopRect := Rect(0,0,Screen.Width,Screen.Height);
   Bitmap := TBitmap.Create;
   with Bitmap do
   begin
     Width := Screen.Width;
     Height:= Screen.Height;
     PixelFormat := pfDevice;
   end;
   Bitmap.Canvas.CopyRect(DeskTopRect,DeskTopCanvas,DeskTopRect);
   Bitmap.SaveToFile ('c:\temp\sample.bmp');
   Bitmap.Free;
   DesktopCanvas.Free;
   ReleaseDC(GetDeskTopWindow,DeskTopDC);
 end;

Generated 8:03:24 on Dec 19, 2018