admin管理员组

文章数量:1415476

I'm trying to capture the desktop screenshot. However, I keep getting a black rectangle. I've also tried plugging out my 2nd monitor to no success, in case it was capturing the laptop screen (which is non-displaying). I've also tried to run the app in Administrator mode with no success.

I've searched the forum with no success, and I want to avoid adding more external libraries for a simple screen capture.

Using Delphi 12.1, Windows 11, 64-bit Firemonkey app.

const 
  CAPTUREBLT = $40000000; // no difference whether used
var
  ScreenBitmap: TBitmap;
  ScreenDC: HDC;
begin
  ScreenBitmap := TBitmap.Create;
  try
    ScreenBitmap.SetSize(300, 300);
    ScreenDC := GetDC(0); // Get the screen DC
    try
      BitBlt(ScreenBitmap.Handle, 0, 0, ScreenBitmap.Width, ScreenBitmap.Height,
             ScreenDC, Round(aRect.Left), Round(aRect.Top), SRCCOPY{ or CAPTUREBLT});
      ScreenBitmap.SaveToFile('test.bmp');
    finally
      ReleaseDC(0, ScreenDC);
    end;
  finally
    ScreenBitmap.Free;
  end;
end;

本文标签: Delphi screen capture part of current screenStack Overflow