Click to See Complete Forum and Search --> : Color Snap
myteoh
May 14th, 2002, 07:13 AM
I wish to build to program which is able snap a point in windows or i should say get a coordinate of that point based on the given color. Do anyone have idea how to do it? Thanks for help.
SLH
May 14th, 2002, 10:56 AM
Do you meen search through a graphic (picbox etc or screen) looking for a certain colour?
myteoh
May 14th, 2002, 11:05 AM
yes. I think WinAPI can do it but i dont know which command to use. Please give me an example code if you can. Thanks again for help.
Gaming_World
May 14th, 2002, 11:29 AM
use the GetPixel API (or you can use the point method of pictureboxes/forms).
Sastraxi
May 14th, 2002, 03:03 PM
That won't help much - he needs to know how.
Ok, add the declaration from the API viewer as you would any other API call. Then, use the function like below. Remember you'll also have to get the PointAPI declaration from the Types field of the API viewer:Function SearchForColour(ByRef mPic As PictureBox, ByRef Ret() As PointAPI, ByRef Colour As Long)
Dim X As Long
Dim Y As Long
Dim Count As Long
mPic.ScaleMode = 3 'vbPixels
For Y = 0 To mPic.ScaleHeight
For X = 0 To mPic.ScaleWidth
If GetPixel(X, Y, mPic.hDC) = Colour Then
Count = Count + 1
Redim Preserve Ret(0 To Count - 1) As PointAPI
With Ret(Count - 1)
.X = X
.Y = Y
End With
Next X
Next YThe code hasn't been tested, but should work. Just go through the Ret() array, just Ret(0) if you aren't expecting more than 1 match. You might use it like this:Dim myArr() As PointAPI
Dim I As Long
On Error Goto NoBlack
SearchForColour Picture1, myArr, RGB(0, 0, 0)
For I = LBound(myArr) To UBound(myArr)
Msgbox "Pure Black found at X: " & myArr(I).X & " Y: " & myArr(I).Y & ".", , "Black Found!"
Next I
NoBlack:
Msgbox "No Pure Black in Picturebox!", , "No Black!"
SLH
May 14th, 2002, 03:08 PM
Don't forget the Extra type used there!
Public Type POINTAPI
x As Long
y As Long
End Type
myteoh
May 15th, 2002, 05:14 AM
I think those example is sufficient for me to build the program. I appreciate the advises from you guys and thanks a lot. :)
Sastraxi
May 15th, 2002, 09:13 PM
Ok, add the declaration from the API viewer as you would any other API call. Then, use the function like below. Remember you'll also have to get the PointAPI declaration from the Types field of the API viewer:
SLH - ;)
SLH
May 16th, 2002, 01:49 AM
:eek: :rolleyes:
Ah well, may have saved him some time.... or not :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.