There is a task to read the pixel color from the BMP file, which is placed in image1 . It is necessary to use for reading the TMemoryStream file, since there is no possibility to use image1.Canvas.Pixels[x,y] - the βpipetteβ is disabled when the DirectX application is running, but it is also started from BMP and taken as a screenshot.
Addition!!!
It turned out that - taking the color Bitmap.Pixels began to work once every other time. What could be the problem? In general: I compile the application, run it from the ΠΈΠΌΠ΅Π½Π° Π°Π΄ΠΌΠΈΠ½Π° - PostMessage does not work, the color returns zeros. I close the application. I start it on a new one - and that works. And so all the time. Previously, the same behavior was noticed in the TICQ module - I didnβt want to log in once every time I started it. What could it be? As you can see, I do not edit the code between runs , and I do not even compile . Just restart and either everything works or everything does not work. I have a Delphi XE3 and Win10 .
So. The code sections do not always work ( I run on ΠΈΠΌΠ΅Π½ΠΈ Π°Π΄ΠΌΠΈΠ½Π° ), but sometimes they work when the application is repeatedly restarted :
procedure TForm1.F10Timer(Sender: TObject); var wnd: HWND; begin wnd:=FindWindow(0, 'Lineage II'); //Π½Π°Ρ
ΠΎΠ΄ΠΈΠΌ ΠΎΠΊΠ½ΠΎ if (wnd<>0) then //Π΅ΡΠ»ΠΈ Π½Π°ΠΉΠ΄Π΅Π½ΠΎ ΡΠΎ Π²ΡΠΏΠΎΠ»Π½ΡΠ΅ΠΌ ΠΊΠΎΠ΄ (Π½Π°Ρ
ΠΎΠ΄ΠΈΡ Π²ΡΠ΅Π³Π΄Π°) begin PostMessage(wnd,WM_KEYDOWN, VK_f10,0); //Π½Π°ΠΆΠΈΠΌΠ°Π΅ΠΌ F10 label14.Caption:='F10'; //Π΄Π»Ρ ΡΠ΅Π±Ρ ΠΏΠΈΡΠ΅ΠΌ Π½Π° ΡΠΎΡΠΌΠ΅ ΡΡΠΎ ΠΊΠ»Π°Π²ΠΈΡΠ° Π½Π°ΠΆΠ°ΡΠ° end; end; There are many such procedures, they are identical, and all together or work or not. They actually send keystrokes to the game window (yes, I am writing a bot).
Next is the definition of color. It only works if sending keystrokes works (I mean this bug, which I described above):
procedure TForm2.Button5Click(Sender: TObject); var GetSc:Dx.TImageCatcher; begin GetSc:=Dx.TImageCatcher.Create; //ΡΠΎΠ·Π΄Π°Ρ ΡΠΊΠ·Π΅ΠΌΠΏΠ»ΡΡ ΠΊΠ»Π°ΡΡΠ° (Dx.pas) GetSc.TargetHandle:=FindWindow(0, 'Lineage II'); //ΠΏΠ΅ΡΠ΅Π΄Π°Ρ Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΠΊ ΠΈΠ³ΡΡ GetSc.CatchType:=ctDirectX; //ΡΡΡΠ°Π½ΠΎΠ²ΠΈΠ» ΡΠΏΠΎΡΠΎΠ± ΡΡΠ΅ΠΌΠΊΠΈ GetSc.ActivateTarget; //Π°ΠΊΡΠΈΠ²ΠΈΡΡΡ ΠΎΠΊΠ½ΠΎ ΠΈΠ³ΡΡ GetSc.GetScreenShot; //ΡΡΠΎ Π±ΠΈΡΠΌΠ°ΠΏ, ΡΡΠ΄Π° Π³ΡΡΠ·ΠΈΠΌ ΡΠ½ΠΈΠΌΠΎΠΊ image1.Picture.Bitmap:=GetSc.Bitmap; //ΠΈΠ· Π±ΠΈΡΠΌΠ°ΠΏΠ° ΠΏΠ΅ΡΠ΅Π΄Π°Π΅ΠΌ ΡΠ½ΠΈΠΌΠΎΠΊ Π² image1 image1.canvas.CopyRect(image1.ClientRect,image1.Canvas,rect(27,58,181,95)); //ΠΎΡΡΠ°Π²Π»ΡΡ Π² image1 ΡΠΎΠ»ΡΠΊΠΎ ΠΈΠ½ΡΠ΅ΡΠ΅ΡΡΡΡΡΡ ΠΌΠ΅Π½Ρ ΠΎΠ±Π»Π°ΡΡΡ (ΡΠΊΠ°Π»Π° CP, HP, MP) image1.Picture.bitmap.width:=155; //ΡΠΎΠ²Π½ΡΠ΅ΠΌ ΡΠ°Π·ΠΌΠ΅ΡΡ image1.Picture.bitmap.Height:=38; //ΡΠΎΠ²Π½ΡΠ΅ΠΌ ΡΠ°Π·ΠΌΠ΅ΡΡ image1.Picture.Bitmap.Dormant; //ΠΏΠ΅ΡΠ΅Π²ΠΎΠ΄ΠΈΠΌ image1 ΠΏΠΎ ΡΠΎΠ²Π΅ΡΡ ΠΈΠ· ΠΊΠ°ΠΌΠΌΠ΅Π½ΡΠΎΠ² labelededit1.Text:=inttohex(image1.Picture.Bitmap.Canvas.Pixels[135,19],6); //ΠΏΡΠΎΠ±ΡΠ΅ΠΌ ΡΠ·Π½Π°ΡΡ ΡΠ²Π΅Ρ end; In fact, here is the whole example, everything else is similar. There is an opinion that either the compiler is sinning or WinAPI, I can not understand. This all sometimes works great, if you start working, and the result here is it:
Window link: https://drive.google.com/open?id=0B3g0HJYW_bzHcnNHWEtTMDVxdXc
Lineage II in the list of windows. Window "Lineage II" class "L2UnrealWWindowsViewportWindow". We see no children.
Link: https://drive.google.com/file/d/0B3g0HJYW_bzHNU1LX3lqWDlfZ2M/view?usp=sharing
DirectXrunning, taking a pixel color from a point on the screen or fromimage1using the above method returns the color code000000tohex. - Arthur Alekseenkoimage1.Picture.Bitmap.Dormant- this converts the bitmap to DIB, and then get access throughimage1.Picture.Bitmap.Canvas.Pixels. Working with binary bitmap content is a thankless task. The location of the bytes of a particular pixel depends on the bitmap bit depth and other factors. - kamiimage:image1.Picture.Graphic:=GetSc.Bitmap;The image is displayed normally.GetSc.Bitmapis a method from a unit with which I useDirectXpull an image outZ-Π±ΡΡΠ΅ΡΠ°game'sZ-Π±ΡΡΠ΅ΡΠ°. Now I will try your advice and accomplish your goal! Thank! - Arthur AlekseenkoDormant, but instead of color in the end,000000. I already broke my whole head, I canβt even imagine what to do with it and why. - Arthur AlekseenkoHPbar isHPI'm trying to get the color of the dot. These two images fly intoimage1andimage2fromDirectX. As seen inLabeledEdit"Color HP" - instead of color zeros. I close the game and try to screen any other window - the color is correct. - Arthur Alekseenko