Vb.net chercher un pixel sur l'ecran

Fermé
asya1002 Messages postés 4 Date d'inscription mercredi 3 octobre 2012 Statut Membre Dernière intervention 5 octobre 2012 - 3 oct. 2012 à 18:07
Bonjour, je suit sur un petit projet et j'ai besoin de connaitre la couleur d'un pixel preci sur l'ecran et de pouvoir rechercher une couleur particuliére sur l'ecran (dans une zone predefini) jai fait sa mai sa ne fonctionne pas (la couleur retourner est toujiur le blanc
qqn pourai me dire ce qui va pas?

(getpixelcolor sert a obetenir la couleur d'un pixel et pixelscreache sert a recherche un pixel)
"
Public Class pixel
Private Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As IntPtr, ByVal X As Int32, ByVal Y As Int32) As Int32
Private Declare Function GetDC Lib "user32" (ByVal hWnd As IntPtr) As IntPtr

Private desktopDc As IntPtr

Public Function GetPixelColor(ByVal pixel As Point)
Dim pt As Point = pixel
Dim colorVal As Int32 = GetPixel(desktopDc, CType(pt.X, Int16), CType(pt.Y, Int16))
Dim r As Int32 = colorVal And &HFF
Dim g As Int32 = (colorVal And &HFF00) >> 8
Dim b As Int32 = (colorVal And &HFF0000) >> 16
Dim c As Color = Color.FromArgb(r, g, b)
Return c
End Function

Public Function PixelScreach(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer, ByVal color As Color)
Dim ret As Point = New Point(-1, -1)
Dim w As Integer = x2 - x1
Dim h As Integer = y2 - y1
Dim c As Color
For a As Integer = 0 To w
For b As Integer = 0 To h
c = GetPixelColor(New Point(w + x1, h + y1))
If c = color Then
Return c
Exit Function
End If
Next
Next
Return ret
End Function
End Class
"



A voir également: