最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Delphi screen capture part of current screen - Stack Overflow

programmeradmin2浏览0评论

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;
发布评论

评论列表(0)

  1. 暂无评论