|
You last visited: Today at 08:13
Advertisement
Bluestack getpixelcolor background not work
Discussion on Bluestack getpixelcolor background not work within the AutoIt forum part of the Coders Den category.
04/01/2016, 00:12
|
#1
|
elite*gold: 0
Join Date: Nov 2007
Posts: 18
Received Thanks: 0
|
Bluestack getpixelcolor background not work
i'm trying create bot for dragon blaze but i cant get getpixelcolor background work the bot doesnt click at position i wanted
the code not work right sometime always click at position
#include <Color.au3>
#include <Math.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Region ### START Koda GUI section ### Form=
$frm = GUICreate("Test", 240, 73, 523, 402)
$Start = GUICtrlCreateButton("Start", 16, 16, 97, 33)
$Stop = GUICtrlCreateButton("Stop", 128, 16, 89, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $hBitmap; Image for pixel functions
Global $hHBitmap; Handle Image for pixel functions
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Start
If _ColorCheck(_GetPixelColor(572, 747), Hex(0xB6CFC7, 6), 1) Then
ToolTip('woot work',0,0)
MouseClick("left", 572, 747, 1 ,1)
EndIf
Case $Stop
Exit
EndSwitch
WEnd
Func _ColorCheck($nColor1, $nColor2, $sVari = 5); checking match between 2 colors (with a variance degree)
Local $Red1, $Red2, $Blue1, $Blue2, $Green1, $Green2
$Red1 = Dec(StringMid(String($nColor1), 1, 2))
$Blue1 = Dec(StringMid(String($nColor1), 3, 2))
$Green1 = Dec(StringMid(String($nColor1), 5, 2))
$Red2 = Dec(StringMid(String($nColor2), 1, 2))
$Blue2 = Dec(StringMid(String($nColor2), 3, 2))
$Green2 = Dec(StringMid(String($nColor2), 5, 2))
If Abs($Blue1 - $Blue2) > $sVari Then Return False
If Abs($Green1 - $Green2) > $sVari Then Return False
If Abs($Red1 - $Red2) > $sVari Then Return False
Return True
EndFunc
Func _GetPixelColor($iX, $iY);Get the piwel colors at specific coordinate
_GDIPlus_Startup(); Initialize GDI+ library
Local $aPixelColor = _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
_GDIPlus_Shutdown(); Shut down GDI+ library
Return Hex($aPixelColor, 6)
EndFunc
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>>>> Window <<<<
Title: BlueStacks App Player
Class: WindowsForms10.Window.8.app.0.33c0d9d
Position: 20, 20
Size: 866, 749
Style: 0x16CA0000
ExStyle: 0x00050100
Handle: 0x00000000003D1620
>>>> Control <<<<
Class:
Instance:
ClassnameNN:
Name:
Advanced (Class):
ID:
Text:
Position:
Size:
ControlClick Coords:
Style:
ExStyle:
Handle:
>>>> Mouse <<<<
Position: 840, 629
Cursor ID: 0
Color: 0xB6CFC7
|
|
|
04/01/2016, 01:13
|
#2
|
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 166
|
Func _GetPixelColor($iX, $iY);Get the piwel colors at specific coordinate
_GDIPlus_Startup(); Initialize GDI+ library
Local $aPixelColor = _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
_GDIPlus_Shutdown(); Shut down GDI+ library
Return Hex($aPixelColor, 6)
EndFunc
Which bitmap are u using if never initialize $hBitmap (=
|
|
|
04/02/2016, 08:38
|
#3
|
elite*gold: 0
Join Date: Nov 2007
Posts: 18
Received Thanks: 0
|
you mean $hBitmap = "BlueStacks App Player" ?
|
|
|
04/03/2016, 00:19
|
#4
|
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 166
|
No, u need to take a screenshot of the bluestacks window.
that won't work if the window is minimized since it won't draw the window.
1) First move the window away from desktop with winmove($winHandle,"",@desktopwidth -100,@desktopheight),
2)take the screenshot, convert the hdc to bitmap so u can get pixel colors of the window
3)check what u want.
I think this code is not yours this is why u ask for something that u don't know...
|
|
|
04/03/2016, 01:17
|
#5
|
elite*gold: 0
Join Date: Nov 2007
Posts: 18
Received Thanks: 0
|
yah code not mine i'm trying to figure out how it work
|
|
|
04/03/2016, 05:38
|
#6
|
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 166
|
Try this
Code:
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <Color.au3>
#include <Math.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
_GDIPlus_Startup()
Global Const $GAME_WIDTH = 866 ;change this to your bluestacks width
Global Const $GAME_HEIGHT = 749;height
Global Const $BLUESTACKS_HWND = WinGetHandle("BlueStacks App Player");change this to your blue stacks name, when in a game it may change window name
#Region ### START Koda GUI section ### Form=
$frm = GUICreate("Test", 240, 103, 523, 402)
$Start = GUICtrlCreateButton("Start", 16, 16, 97, 33)
$Stop = GUICtrlCreateButton("Stop", 128, 16, 89, 33)
$Restore = GUICtrlCreateButton("Restore",70,60,100,40)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Start
If _ColorCheck(_GetPixelColor(572, 747), Hex(0xB6CFC7, 6), 1) Then
ToolTip('woot work',0,0)
MouseClick("left", 572, 747, 1 ,1)
EndIf
Case $Restore ;U need this cause the capture game window func will hide the window
WinActivate($BLUESTACKS_HWND)
WinMove($BLUESTACKS_HWND,"",0,0)
Case $Stop
Exit 0
EndSwitch
WEnd
Func _ColorCheck($nColor1, $nColor2, $sVari = 5); checking match between 2 colors (with a variance degree)
Local $Red1, $Red2, $Blue1, $Blue2, $Green1, $Green2
$Red1 = Dec(StringMid(String($nColor1), 1, 2))
$Blue1 = Dec(StringMid(String($nColor1), 3, 2))
$Green1 = Dec(StringMid(String($nColor1), 5, 2))
$Red2 = Dec(StringMid(String($nColor2), 1, 2))
$Blue2 = Dec(StringMid(String($nColor2), 3, 2))
$Green2 = Dec(StringMid(String($nColor2), 5, 2))
If Abs($Blue1 - $Blue2) > $sVari Then Return False
If Abs($Green1 - $Green2) > $sVari Then Return False
If Abs($Red1 - $Red2) > $sVari Then Return False
Return True
EndFunc
Func _GetPixelColor($iX, $iY);Get the piwel colors at specific coordinate
$hBitmap = CaptureGameWindow() ;the bitmap will be obtained capturing the game window
Local $aPixelColor = _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
display($hBitmap) ;Remove this when u get the right screenshot bitmap
Return Hex($aPixelColor, 6)
EndFunc
Func display($hBitmap)
Local $tempGui = GUICreate("",_GDIPlus_ImageGetWidth($hBitmap),_GDIPlus_ImageGetHeight($hBitmap)) ;creates a gui to display the capture, just to see what u get, delete when no need any more
GUISetState();show the gui
Local $tempGraphic = _GDIPlus_GraphicsCreateFromHWND($tempGui);graphics to draw capture bitmap
_GDIPlus_GraphicsDrawImage($tempGraphic,$hBitmap,0,0);draws the image to the graphics inside the gui
Sleep(2500);shows for 2.5seg then delete
GUIDelete($tempGui); delete the gui
EndFunc
Func CaptureGameWindow()
WinMove($BLUESTACKS_HWND,"",0,0);Move window to 0 0 on screen
WinSetOnTop($BLUESTACKS_HWND,"",1);set it on top
$HBMP = _ScreenCapture_CaptureWnd("",$BLUESTACKS_HWND,0,0,$GAME_WIDTH,$GAME_HEIGHT) ;capture
WinSetOnTop($BLUESTACKS_HWND,"",0) ;set it not on top
WinMove($BLUESTACKS_HWND,"",@DesktopWidth-100,@DesktopHeight);move away from view, it's not minimized but u cannot see it anyway... (check bottom)
$bmp = _GDIPlus_BitmapCreateFromHBITMAP($HBMP); we need the bitmap to get pixel colors
Return $bmp
EndFunc
|
|
|
04/04/2016, 01:19
|
#7
|
elite*gold: 0
Join Date: Nov 2007
Posts: 18
Received Thanks: 0
|
thanks elemarcia got it work now
|
|
|
All times are GMT +2. The time now is 08:13.
|
|