2010. szeptember 24., péntek

Screen capture into a BMP file


Screen capture into a BMP file


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);
  DeskTopDC: HDc;
  DeskTopCanvas: TCanvas;
  DeskTopRect: TRect;
  Bitmap: TBitmap;
  DeskTopDC := GetWindowDC(GetDeskTopWindow);
  DeskTopCanvas := TCanvas.Create;
  DeskTopCanvas.Handle := DeskTopDC;
  DeskTopRect := Rect(0, 0, Screen.Width, Screen.Height);
  Bitmap := TBitmap.Create;
  with Bitmap do
    Width := Screen.Width;
    Height := Screen.Height;
    PixelFormat := pfDevice;
  Bitmap.Canvas.CopyRect(DeskTopRect, DeskTopCanvas, DeskTopRect);
  ReleaseDC(GetDeskTopWindow, DeskTopDC);

Nincsenek megjegyzések:

Megjegyzés küldése