How do i check what color the pixel is in a certain size box? I want to make a box that is about 100x100 pixels in the center of the screen, that checks for certain colors then if it detects them it executes a function.
Printable View
How do i check what color the pixel is in a certain size box? I want to make a box that is about 100x100 pixels in the center of the screen, that checks for certain colors then if it detects them it executes a function.
VB Code:
Declare Function GetPixel.... () ... 'whatever goes here! Type RECT Left as Long Right as Long Top as Long Bottom as Long End Type Function Check(R as RECT) 'R is the box that you have, for a 100x100 set this to .bottom = 100, .right = 100 Dim A Dim H For A = R.Top to R.Bottom For H = R.Left to R.Right If GetPixel(mypicturebox.hDC, A, H) = RGB(0,0,0) Then 'checks for black Myfunction() Exit For Exit For Exit Function End If Next H Next A End Function
Here's the API declaration...
alternatively you can use the picture point method...Code:Declare Function GetPixel Lib "gdi32" Alias "GetPixel" _
(ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
- Dim ACode:if picture1.point(x,y)=vbblack then