Nun hat das Bild die korrekte Größe, ohne den "Freiraum"
Delphi-Quellcode:
procedure ScreenShot(const AActiveWindow: Boolean; var ADestBitmap: TBitmap);
var
w, h: Integer;
hWin: HWND;
r: TRect;
oDC: HDC;
oCanvas: TCanvas;
oBitmap: TBitmap;
BorderHeight,
BorderWidth: Integer;
begin
if AActiveWindow then
hWin := GetForegroundWindow
else
hWin := GetDesktopWindow;
try
GetWindowRect(hWin, r);
if AActiveWindow then
begin
BorderHeight := GetSystemMetrics(SM_CXDLGFRAME) + GetSystemMetrics(SM_CXSIZEFRAME) + GetSystemMetrics(SM_CXEDGE);
BorderWidth := GetSystemMetrics(SM_CYDLGFRAME) + GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYEDGE);
r.Right := r.Right - BorderWidth;
r.Left := r.Left + BorderWidth;
r.Bottom := r.Bottom - BorderHeight;
end;
w := r.Right - r.Left;
h := r.Bottom - r.Top;
oCanvas := TCanvas.Create;
try
oDC := GetDC(0);
try
oBitmap := TBitmap.Create;
try
oBitmap.PixelFormat := TPixelFormat.pfDevice;
oBitmap.Width := w;
oBitmap.Height := h;
oCanvas.Handle := oDC;
oBitmap.Canvas.CopyMode := cmSrcCopy;
oBitmap.Canvas.CopyRect(
Rect(0, 0, oBitmap.Width, oBitmap.Height),
oCanvas,
Rect(r.Left, r.Top, r.Right, r.Bottom));
finally
ADestBitmap.Assign(oBitmap);
oBitmap.Free;
end;
finally
ReleaseDC(0, oDC);
end;
finally
oCanvas.Free;
end;
finally
end;
end;
Ich hoffe es hilft, viel Spaß damit!