|
-
Jan 3rd, 2007, 05:35 AM
#1
Thread Starter
New Member
GetPixel...Different Issue
I have read through at least 20 GetPixel API threads on this forum as well as other places on the internet and I must say, I have made no progress. I started out writing macros for games mainly relying on color checks, loading the RGB value of a specific pixel in a game, namely World of Warcraft, and then comparing it.
I can't seem to find out however how to use the VB6 API GetPixel. Basically, I am trying to load a pixel, lets say, 500, 400. Then I want to ask, is it the RED Value = 100. If not, delay, or whatever. I know how to do all of this and I am not for one second asking for anyone to write me a macro as I find learning Visual Basic is fun, I am just extremely confused as to how I go about doing this whole color check buisness.
Thank you very much for your reply and please don't link me to the example vault as I have studied and tried to understand it many times already. Thank you!!!
-Wizzel
Last edited by Wizzel; Jan 5th, 2007 at 02:22 AM.
-
Jan 3rd, 2007, 06:19 AM
#2
Hyperactive Member
Re: GetPixel...Different Issue
-
Jan 3rd, 2007, 08:45 AM
#3
Hyperactive Member
Re: GetPixel...Different Issue
RGBx values are all stored together stored as a single Long and you need to do some tinkering to get each color..
VB Code:
r = lColor And &HFF
g = lColor \ &H100 And &HFF
b = lColor \ &H10000 And &HFF
For your situation, GetPixel() should return its value in lColor format
-
Jan 4th, 2007, 11:27 PM
#4
Thread Starter
New Member
Re: GetPixel...Different Issue
Thanks for the replies guys. I am still a bit confused. Specifically, for example, I want the program to lets say if the pixel at 355, 400 has an RGB value of:
R:250
G:255
B:10
I want the program to respond to that by doing a certain action. I used another scripting language, not VB, but I am still trying to convert the action. The example above of the program is not quite what i want but still encompasses the same ideas where it gathers the RGB values from the image. I don't want simply an image, I want it to gather the value of a single pixel from the entire screen.
Thank you so much for your replies. I would post my attempts but they don't work at all. Thank you.
-Wizzel
-
Jan 5th, 2007, 12:59 AM
#5
Hyperactive Member
Re: GetPixel...Different Issue
if getpixel(355,400) = &h0AFFFA then dostuff
Should do what you need.. Remember rgb's are stored in a single Long that you can think of as BBGGRR if written in hex.. It seems more confusing in decimal since 255 doesn't work nicely with base 10 math, but if you look at vb's big number for 255,255,255.. You'll notice it actually equals 255*255*255 just like &HFFFFFF actually equals FF*FF*FF, and FF=255 in Hexadecimal btw..
-
Jan 5th, 2007, 02:15 AM
#6
Thread Starter
New Member
Re: GetPixel...Different Issue
 Originally Posted by triggernum5
if getpixel(355,400) = &h0AFFFA then dostuff
Should do what you need.. Remember rgb's are stored in a single Long that you can think of as BBGGRR if written in hex.. It seems more confusing in decimal since 255 doesn't work nicely with base 10 math, but if you look at vb's big number for 255,255,255.. You'll notice it actually equals 255*255*255 just like &HFFFFFF actually equals FF*FF*FF, and FF=255 in Hexadecimal btw..
Thanks a bunch for the example. What is an easy way to convert numbers to hexadecimal format? Thanks again.
-
Jan 5th, 2007, 02:25 AM
#7
Hyperactive Member
Re: GetPixel...Different Issue
hex(decimalnumber)
you can plug it into most code directly..
eg: r=hex(255) result is the same as r=&HFF.. r=255 also has the same result.. aside from type issues that might exist, they are basically interchangeable..
-
Jan 5th, 2007, 02:37 AM
#8
Thread Starter
New Member
Re: GetPixel...Different Issue
Awesome...I will try this out tonight and tell you how it goes!
-
Jan 5th, 2007, 04:39 AM
#9
Thread Starter
New Member
Re: GetPixel...Different Issue
Okay, I have tried to understand the whole of this and I have done my best to work up a small bit of code. Just to be a beginner and simple, the program will load, check to see if the pixel has the red value specified, 150, and then if not, it closes. I am pretty sure the flow is fine but the code is not. Any advice and or help would be amazing...thank you.
VB Code:
Option Explicit
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
Sub Form_Load()
If GetPixel(355, 400) = (red=150)
Call Start
Else
Unload Me
End If
Sub Start()
Sleep 1000
End Sub
The problem, or at least the main one is I still don't completely grasp the hex values reflecting certain RGB values. If you can fix my code, could you possibly include just examples of looking for the Green value of 50 or a blue value of 95 or anything, and such, it would give me a better understanding. Also, could I include more checks in 1 operation. If G=10 and B=200, then do this. Thanks again for bearing with me as this is the last step in finishing what I wish to accomplish.
-Alyssa
-
Jan 5th, 2007, 12:31 PM
#10
Hyperactive Member
Re: GetPixel...Different Issue
You still seem to miss the concept of all 3 colors being stored in one value that you have to extract each from.. Imagine that there are only 10 possible values for each red, green, blue.. That means that there are 100 combinations of any 2 of the colors, and 1000 combos of all three.. Then we would use the same method to write color=999 for white (each digit actually represents either r,g,b r=9 g=9 b=9) Hexadecimal colors actually use 2 digits per color component so in our example it would be more like color=999999 giving 100 shades of each color.. Working with 9's is easier for humans, but computers like hexadecimal since FF is a nice round 11111111 (F=1111 btw) so each hex digit nicely transforms into binary..
So with what I posted earlier:
If GetPixel(355, 400) = (red=150) should be
If GetPixel(355, 400) And &HFF = 150 'For Red
If (GetPixel(355, 400))\&h100 And&hFF = 150 'For Green
If (GetPixel(355, 400))\&h10000 And&hFF = 150 'For Blue
Btw, all these maths are doing is knocking unwanted digits off with the divisions and comparing the remainders with the AND operations..
eg
467 \ 100 = 4 '(backslash gives integer division ignoring decimal places that forward slash does not ignore)
467 mod 100 = 67 ' (Mod and AND can be used in similar fashions oftentimes..)
Try to get a grip with the fact that you are using the signifigance of certain digits in a single value for each color, and a basic hexadecimal/binary/decimal conversion tutorial will save you alot of headache if I didn't explain it adequately..
-
Jan 5th, 2007, 01:24 PM
#11
Re: GetPixel...Different Issue
 Originally Posted by Wizzel
VB Code:
Option Explicit
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
Sub Form_Load()
If GetPixel(355, 400) = (red=150)
Call Start
Else
Unload Me
End If
Sub Start()
Sleep 1000
End Sub
The GetPixel function requires an hDC (Device Context Handle) to the window you're getting the pixel from.
You'll need to find the Window handle (hWnd) of the game. Possibly using the FindWindow() API function. This may or may not work depending on the game.
Then you'll need to get the hDC to that window by using the GetDC function. You provide the window handle (hWnd) to this function.
From there you can use the GetPixel API function with that hDC.
And then convert it to RGB using triggers code.
Edit: Logically, it would look something like this:
VB Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Sub Form_Load()
Dim lonHWND As Long 'Handle to game window.
Dim lonDC As Long 'Device context handle of game window.
Dim lonColor As Long 'Color value in long format.
'You'll need to get the class name of the window.
lonHWND = FindWindow("ClassName", "Caption Of Game Window")
If lonHWND <> 0 Then 'Found the window?
lonDC = GetDC(lonHWND) 'Get device context handle.
If lonDC <> 0 Then 'Got the DC?
lonColor = GetPixel(lonDC, 350, 400)
'Now convert to RGB.
End If
End If
End Sub
Last edited by DigiRev; Jan 5th, 2007 at 01:29 PM.
-
Jan 5th, 2007, 03:09 PM
#12
Thread Starter
New Member
Re: GetPixel...Different Issue
Thank you both for your replies. I will rewrite the code, do some more research and try again. Thank you again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|