Home > Back-end >  Why BMP interception to another BMP is not successful.
Why BMP interception to another BMP is not successful.

Time:10-02

Code is a rectangular area corresponding to the bmp1 BMP,
But you don't succeed, bmp1 is blank
Because it is a game, so can't use ordinary PrintScree

 procedure CaptureScreen (AFileName: string); 
Const
CAPTUREBLT=$40000000;
Var
HdcScreen: HDC;
HdcCompatible: HDC;
BMP, bmp1: TBitmap;
HbmScreen: HBITMAP;
The hWnd: THandle;
RGame: TRect;
The 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, 'underground city and warrior');
If hWnd & gt; 0 then
The begin
GetWindowRect (hWnd, rGame);

Bmp1. Width:=rGame. Right - rGame. Left;
Bmp1. Height:=rGame. Bottom - rGame. Top;

Bmp1. Canvas. CopyRect (the Rect (0, 0, rGame. Right, rGame. The Bottom), BMP, Canvas, rGame);

Bmp1. SaveToFile (AFileName);
End the else
The begin
BMP. SaveToFile (AFileName);
The end;

BMP. Free;
Bmp1. Free;
DeleteDC (hdcScreen);
DeleteDC (hdcCompatible);
The end;

CodePudding user response:

The game is not with them the way to screenshots,

CodePudding user response:

The game? Based on the dx?
It is different from the practice of normal window procedure

CodePudding user response:

No,
The screenshots, can cut to DX game picture,
But is a full screen,
In BMP,
I think part of the game in the BMP in the screenshot to bmp1,
The crux of the problem in this section:
 hWnd:=FindWindow (nil, 'underground city and warrior'); 
If hWnd & gt; 0 then
The begin
GetWindowRect (hWnd, rGame);

Bmp1. Width:=rGame. Right - rGame. Left;
Bmp1. Height:=rGame. Bottom - rGame. Top;

Bmp1. Canvas. CopyRect (the Rect (0, 0, rGame. Right, rGame. The Bottom), BMP, Canvas, rGame);

Bmp1. SaveToFile (AFileName);


In the game of a BMP intercepted bmp1, failed to achieve,

CodePudding user response:

BMP save to file, is the content?
Then read back, intercepting again?

CodePudding user response:

HWnd:=FindWindow (nil, 'underground city and warrior');
If hWnd & gt; 0 then
The begin
GetWindowRect (hWnd, rGame);

Bmp1. Width:=rGame. Right - rGame. Left;
Bmp1. Height:=rGame. Bottom - rGame. Top;

Bmp1. Canvas. CopyRect (the Rect (0, 0, rGame. Right, rGame. The Bottom), BMP, Canvas, rGame);

Bmp1. SaveToFile (AFileName);
End the else
The begin
BMP. SaveToFile (AFileName);
The end;
You DebuG the code and see rGame TRect=the packed record
In case the Integer of
0: (Left, Top, Right, Bottom: Longint);
1: (TopLeft, BottomRight: TPoint);
The end;
Did this a few parameters values

CodePudding user response:

reference 5 floor yc515623876 reply:
hWnd:=FindWindow (nil, 'underground city and warrior');
If hWnd & gt; 0 then
The begin
GetWindowRect (hWnd, rGame);

Bmp1. Width:=rGame. Right - rGame. Left;
Bmp1. Height:=rGame. Bottom - rGame. Top;

Bmp1. Canvas. CopyRect (the Rect (0, 0, rGame. Right, rGame. The Bottom), BMP, Canvas, rGame);

Bmp1. SaveToFile (AFileName);
End the else
The begin
BMP. SaveToFile (AFileName);
The end;
You DebuG the code and see rGame TRect=the packed record
In case the Integer of
0: (Left, Top, Right, Bottom: Longint);
1: (TopLeft, BottomRight: TPoint);
The end;
Did this a few parameters values


Have a value

CodePudding user response:

The
reference 4 floor sz_haitao reply:
BMP save to file, is the content?
Then read back, intercepting again?


BMP free capacity, directly to the BMP save to file, is the whole screen screenshots,

CodePudding user response:

Intercept try the BitBlt
 
Procedure CropBitmap (InBitmap, OutBitMap: TBitmap; X, Y, W, H: Integer);
The 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);
The end;
  • Related