1,183
社区成员
发帖
与我相关
我的任务
分享
procedure CaptureScreen(AFileName: string);
const
CAPTUREBLT = $40000000;
var
hdcScreen: HDC;
hdcCompatible: HDC;
bmp,bmp1: TBitmap;
hbmScreen: HBITMAP;
hWnd: THandle;
rGame : TRect;
begin
hdcScreen := CreateDC('DISPLAY', nil, nil, nil);
hdcCompatible := CreateCompatibleDC(hdcScreen);
hbmScreen := CreateCompatibleBitmap(hdcScreen,
GetDeviceCaps(hdcScreen, HORZRES),
GetDeviceCaps(hdcScreen, VERTRES));
SelectObject(hdcCompatible, hbmScreen);
bmp := TBitmap.Create;
bmp1 := TBitmap.Create;
bmp.Handle := hbmScreen;
BitBlt(hdcCompatible,
0, 0,
bmp.Width, bmp.Height,
hdcScreen,
0, 0,
SRCCOPY or CAPTUREBLT);
hWnd := FindWindow(nil, '地下城与勇士');
if hWnd > 0 then
begin
GetWindowRect(hWnd,rGame);
bmp1.Width := rGame.Right - rGame.Left;
bmp1.Height := rGame.Bottom - rGame.Top;
bmp1.Canvas.CopyRect(Rect(0,0,rGame.Right,rGame.Bottom),bmp.Canvas,rGame);
bmp1.SaveToFile(AFileName);
end else
begin
bmp.SaveToFile(AFileName);
end;
bmp.Free;
bmp1.Free;
DeleteDC(hdcScreen);
DeleteDC(hdcCompatible);
end;
procedure CropBitmap(InBitmap, OutBitMap : TBitmap; X, Y, W, H :Integer);
begin
OutBitMap.PixelFormat := InBitmap.PixelFormat;
OutBitMap.Width := W;
OutBitMap.Height := H;
BitBlt(OutBitMap.Canvas.Handle, 0, 0, W, H, InBitmap.Canvas.Handle, X, Y, SRCCOPY);
end;
hWnd := FindWindow(nil, '地下城与勇士');
if hWnd > 0 then
begin
GetWindowRect(hWnd,rGame);
bmp1.Width := rGame.Right - rGame.Left;
bmp1.Height := rGame.Bottom - rGame.Top;
bmp1.Canvas.CopyRect(Rect(0,0,rGame.Right,rGame.Bottom),bmp.Canvas,rGame);
bmp1.SaveToFile(AFileName);
在将bmp中游戏部份截取到bmp1时,没能实现。