En fait je souhaiterai qu'il parcours toute la largeur X de l'écran, une fois arrivé a droite, il descend d'un pixel sur la ligne Y, jusqu'a arrivé à x=1279 & y = 760, ou meme mieu, sans lui donné les dimentions de l'écran.
Dim b As New Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height) Dim g As Graphics = Graphics.FromImage(b) g.CopyFromScreen(New Point(0, 0), New Point(0, 0), Screen.PrimaryScreen.WorkingArea.Size) For x = 0 To b.Width - 1 For y = 0 To b.Height - 1 If b.GetPixel(x, y) = Color.FromArgb(255, 255, 255) Then MessageBox.Show(String.Format("Couleur blanche trouvée sur x={0} et y={1}", x, y)) End If Next Next
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp Dim pt As Point = MousePosition() 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) 'change la couleur de fond de la form Me.BackColor = c Label1.Text = "R,G,B= " & r & ", " & g & ", " & b Label2.Text = "mouse(x,y)= " & MousePosition.X & " " & MousePosition.Y End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick Dim colorVal As Int32 = GetPixel(desktopDc, CType(LocationX, Int16), CType(LocationY, 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) If Label1.Text.Contains("255, 255, 255") Then 'si je tombe sur un pixel de la couleur rvb(255,255,255), je m'en informe via messagebox. Timer2.Enabled = False Timer2.Stop() MessageBox.Show("couleur trouvé en " & LocationX & "," & LocationY) Else If LocationX = 1279 Then LocationY += 1 LocationX = 0 Else LocationX += 1 Label1.Text = "R,G,B= " & r & ", " & g & ", " & b Label2.Text = "mouse(x,y)= " & LocationX & " " & LocationY Me.BackColor = c End If End If
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionC'est l'utilisation d'API qui réduit la vitesse ?Je ne sais pas.
Dim b As New Bitmap(Screen.PrimaryScreen.WorkingArea.Width / 2, Screen.PrimaryScreen.WorkingArea.Height /2) Dim g As Graphics = Graphics.FromImage(b)
BackgroundWorker1.RunWorkerAsync()
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Timer1.Enabled = False Timer1.Stop() rvb() End Sub
Module ChercheColorPixel Private Declare Function SetCursorPos& Lib "user32" (ByVal X As Integer, ByVal Y As Integer) Dim Debut As String Dim Fin As String Dim d As String Dim RR As String Dim VV As String Dim BB As String Private desktopDc As IntPtr Sub rvb() Dim b As New Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height) Dim g As Graphics = Graphics.FromImage(b) g.CopyFromScreen(New Point(0, 0), New Point(0, 0), Screen.PrimaryScreen.WorkingArea.Size) d = "<CherchePixelColor> r=" 'd=chaine début Debut = InStr(1, Boss.ListBoxExecute.SelectedItem, d) ' Position du < Fin = InStr(1, Boss.ListBoxExecute.SelectedItem, ",v=") ' Position du <debutx = RR = Mid$(Boss.ListBoxExecute.SelectedItem, Debut + d.Length, Fin - Debut - d.Length) d = ",v=" 'd=chaine début Debut = InStr(1, Boss.ListBoxExecute.SelectedItem, d) ' Position du < Fin = InStr(1, Boss.ListBoxExecute.SelectedItem, ",b=") ' Position du <debutx = VV = Mid$(Boss.ListBoxExecute.SelectedItem, Debut + d.Length, Fin - Debut - d.Length) d = ",b=" 'd=chaine début Debut = InStr(1, Boss.ListBoxExecute.SelectedItem, d) ' Position du < Fin InStr(1, Boss.ListBoxExecute.SelectedItem, ".") ' Position du <debutx BB = Mid$(Boss.ListBoxExecute.SelectedItem, Debut + d.Length, Fin - Debut - d.Length) Thread.Sleep(200) For x = 0 To b.Width - 1 For y = 0 To b.Height - 1 If b.GetPixel(x, y) = Color.FromArgb(RR, VV, BB) Then Thread.Sleep(200) SetCursorPos&(x, y) Boss.Timer1.Interval = 100 Boss.Timer1.Enabled = True Boss.Timer1.Start() Else Thread.Sleep(200) Boss.Timer1.Enabled = True Boss.Timer1.Interval = 100 Boss.Timer1.Start() Boss.ListBoxExecute.SelectedIndex = Boss.ListBoxExecute.SelectedIndex + 5 End If Next Next End Sub End Module
For x = 0 To b.Width - 1 For y = 0 To b.Height - 1 If b.GetPixel(x, y) = Color.FromArgb(RR, VV, BB) Then SetCursorPos&(x, y) Boss.Timer1.Enabled = True Boss.Timer1.Interval = 100 Boss.Timer1.Start() End If Next Next
Si je depasse les next, c'est qu'il n'y a pas de pixel détécté, c'est ça ?oui
Sinon pour Cursor.Position, fonctionne sur n'importe quelle fenêtre ?Fais donc un essai :
cursor.position = new point(20,20)
messagebox.show(string.format("x={0} y={1}",cursor.position.x,cursor.position.y))