代码是将bmp的相应矩形区域到bmp1上,
但是不成功啊,bmp1是空白的
因为是游戏,所以不能用普通的PrintScreeprocedure 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;
但是不成功啊,bmp1是空白的
因为是游戏,所以不能用普通的PrintScreeprocedure 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;
解决方案 »
- 求救关于DeleteFile函数问题???
- TcpServer和TcpClient通信连接报错的问题
- 我快疯了,delphi 7 经常一启动调试就会死机????
- 我要在一个有年月日的日期里查找只要月日符合的日期的记录。
- 试用delphi的一点体会,感觉现在的borland太不用心了
- QReport中怎么画表格?
- delphi7调用webservice(VS.net) 生成dll文件的函数调用问题
- 怎样分割这条Update语句?
- 报表- 怎么打印当前纪录?
- 怎样使SERVERSOCKET同时响应多个CLIENTSOCKET的请求?
- 谁能帮帮我
- delphi程序编好后,功能一切正常,就是出现一个了小问题,急求解决方案
这个截图,可以截到DX游戏的画面。
但是是全屏幕的,
存放在bmp中,
我想在bmp中将游戏部份再截图到bmp1中。
问题的关键在这一段:
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时,没能实现。
那就再读回来,再截取?
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;
你DebuG下这个代码 看看 rGame的 TRect = packed record
case Integer of
0: (Left, Top, Right, Bottom: Longint);
1: (TopLeft, BottomRight: TPoint);
end;
这几个参数有没有值
bmp有空容,直接将bmp保存到文件,是真个屏幕的截图。
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;