Guten Abend liebe Gemeinde,
ich habe ein Problem und weiß noch nicht ganz wie ich es euch vermitteln kann, da ich selbst nicht weiß, wo es liegt.
Ich habe eine Methode gefunden um Bilder auf dem Desktop zu suchen und dessen Koordinaten zu finden. Auf der Arbeit erleichtert das den Workflow ungemein, aber das ist ja nun erstmal egal.
Folgende Funktion:
Folgender Aufruf:
Klappt bei mir BESTENS. Innerhalb von 200ms hat er das Bild, egal wo es auf meinem Bildschirm ist.
Habe es also meinem Kollegen gesendet, er macht nichts anders, ruft die Funktion auf.. Zack:
Es ist leider nicht möglich auf seinem PC VS zu installieren, da er dafür keine Rechte hat.
Ich habe also hinter alle möglichen Zeilen eine Funktion eingebaut um in eine Textdatei zu schreiben:
Fazit: Er kommt bis "Geht noch 15"..
Habt ihr eine Idee warum? Er hat nichts anders gemacht als ich. Was kann ich noch zum Debuggen tun, ohne VS zu verwenden?
Vielen Dank im Voraus..
Mit freundlichen Grüßen,
xored
EDIT: Wenn ich die For-Schleifen in einen Try-Block packe, kommt natürlich kein Fehler mehr, er sagt aber natürlich, er habe den Button nicht gefunden..
*Topic verschoben*
ich habe ein Problem und weiß noch nicht ganz wie ich es euch vermitteln kann, da ich selbst nicht weiß, wo es liegt.
Ich habe eine Methode gefunden um Bilder auf dem Desktop zu suchen und dessen Koordinaten zu finden. Auf der Arbeit erleichtert das den Workflow ungemein, aber das ist ja nun erstmal egal.
Folgende Funktion:
VB.NET-Quellcode
- Private Function FindImageOnScreen(ByVal bmpMatch As Bitmap, ByVal ExactMatch As Boolean) As Rectangle
- Dim ScreenBmp As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
- Using g As Graphics = Graphics.FromImage(ScreenBmp)
- g.CopyFromScreen(Screen.PrimaryScreen.Bounds.Location, Point.Empty, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)
- End Using
- Dim ImgBmd As BitmapData = bmpMatch.LockBits(New Rectangle(0, 0, bmpMatch.Width, bmpMatch.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb)
- Dim ScreenBmd As BitmapData = ScreenBmp.LockBits(Screen.PrimaryScreen.Bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb)
- Dim ImgByts((Math.Abs(ImgBmd.Stride) * bmpMatch.Height) - 1) As Byte
- Dim ScreenByts((Math.Abs(ScreenBmd.Stride) * ScreenBmp.Height) - 1) As Byte
- Marshal.Copy(ImgBmd.Scan0, ImgByts, 0, ImgByts.Length)
- Marshal.Copy(ScreenBmd.Scan0, ScreenByts, 0, ScreenByts.Length)
- Dim FoundMatch As Boolean = False
- Dim rct As Rectangle = Rectangle.Empty
- Dim sindx, iindx As Integer
- Dim spc, ipc As Integer
- Dim skpx As Integer = CInt((bmpMatch.Width - 1) / 10)
- If skpx < 1 Or ExactMatch Then skpx = 1
- Dim skpy As Integer = CInt((bmpMatch.Height - 1) / 10)
- If skpy < 1 Or ExactMatch Then skpy = 1
- For si As Integer = 0 To ScreenByts.Length - 1 Step 3
- FoundMatch = True
- For iy As Integer = 0 To ImgBmd.Height - 1 Step skpy
- For ix As Integer = 0 To ImgBmd.Width - 1 Step skpx
- sindx = (iy * ScreenBmd.Stride) + (ix * 3) + si
- iindx = (iy * ImgBmd.Stride) + (ix * 3)
- spc = Color.FromArgb(ScreenByts(sindx + 2), ScreenByts(sindx + 1), ScreenByts(sindx)).ToArgb
- ipc = Color.FromArgb(ImgByts(iindx + 2), ImgByts(iindx + 1), ImgByts(iindx)).ToArgb
- If spc <> ipc Then
- FoundMatch = False
- iy = ImgBmd.Height - 1
- ix = ImgBmd.Width - 1
- End If
- Next
- Next
- If FoundMatch Then
- Dim r As Double = si / (ScreenBmp.Width * 3)
- Dim c As Double = ScreenBmp.Width * (r Mod 1)
- If r Mod 1 >= 0.5 Then r -= 1
- rct.X = CInt(c)
- rct.Y = CInt(r)
- rct.Width = bmpMatch.Width
- rct.Height = bmpMatch.Height
- Exit For
- End If
- Next
- bmpMatch.UnlockBits(ImgBmd)
- ScreenBmp.UnlockBits(ScreenBmd)
- ScreenBmp.Dispose()
- Return rct
- End Function
Folgender Aufruf:
Klappt bei mir BESTENS. Innerhalb von 200ms hat er das Bild, egal wo es auf meinem Bildschirm ist.
Habe es also meinem Kollegen gesendet, er macht nichts anders, ruft die Funktion auf.. Zack:
System.IndexOutOfRangeException: Der Index war außerhalb des Arraybereichs.
bei Test.FindImageOnScreen(Bitmap bmpMatch, Boolean ExactMatch)
Es ist leider nicht möglich auf seinem PC VS zu installieren, da er dafür keine Rechte hat.
Ich habe also hinter alle möglichen Zeilen eine Funktion eingebaut um in eine Textdatei zu schreiben:
VB.NET-Quellcode
- Private Function FindImageOnScreen(ByVal bmpMatch As Bitmap, ByVal ExactMatch As Boolean) As Rectangle
- logerrors("Geht noch 0")
- Dim ScreenBmp As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
- logerrors("Geht noch 1")
- Using g As Graphics = Graphics.FromImage(ScreenBmp)
- g.CopyFromScreen(Screen.PrimaryScreen.Bounds.Location, Point.Empty, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)
- logerrors("Geht noch 2")
- End Using
- Dim ImgBmd As BitmapData = bmpMatch.LockBits(New Rectangle(0, 0, bmpMatch.Width, bmpMatch.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb)
- logerrors("Geht noch 3")
- Dim ScreenBmd As BitmapData = ScreenBmp.LockBits(Screen.PrimaryScreen.Bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb)
- logerrors("Geht noch 4")
- Dim ImgByts((Math.Abs(ImgBmd.Stride) * bmpMatch.Height) - 1) As Byte
- logerrors("Geht noch 5")
- Dim ScreenByts((Math.Abs(ScreenBmd.Stride) * ScreenBmp.Height) - 1) As Byte
- logerrors("Geht noch 6")
- Marshal.Copy(ImgBmd.Scan0, ImgByts, 0, ImgByts.Length)
- logerrors("Geht noch 7")
- Marshal.Copy(ScreenBmd.Scan0, ScreenByts, 0, ScreenByts.Length)
- Dim FoundMatch As Boolean = False
- logerrors("Geht noch 8")
- Dim rct As Rectangle = Rectangle.Empty
- logerrors("Geht noch 9")
- Dim sindx, iindx As Integer
- logerrors("Geht noch 10")
- Dim spc, ipc As Integer
- logerrors("Geht noch 11")
- Dim skpx As Integer = CInt((bmpMatch.Width - 1) / 10)
- logerrors("Geht noch 12")
- If skpx < 1 Or ExactMatch Then skpx = 1
- logerrors("Geht noch 13")
- Dim skpy As Integer = CInt((bmpMatch.Height - 1) / 10)
- logerrors("Geht noch 14")
- If skpy < 1 Or ExactMatch Then skpy = 1
- logerrors("Geht noch 15")
- For si As Integer = 0 To ScreenByts.Length - 1 Step 3
- FoundMatch = True
- For iy As Integer = 0 To ImgBmd.Height - 1 Step skpy
- For ix As Integer = 0 To ImgBmd.Width - 1 Step skpx
- sindx = (iy * ScreenBmd.Stride) + (ix * 3) + si
- iindx = (iy * ImgBmd.Stride) + (ix * 3)
- spc = Color.FromArgb(ScreenByts(sindx + 2), ScreenByts(sindx + 1), ScreenByts(sindx)).ToArgb
- ipc = Color.FromArgb(ImgByts(iindx + 2), ImgByts(iindx + 1), ImgByts(iindx)).ToArgb
- If spc <> ipc Then
- FoundMatch = False
- iy = ImgBmd.Height - 1
- ix = ImgBmd.Width - 1
- End If
- Next
- Next
- If FoundMatch Then
- Dim r As Double = si / (ScreenBmp.Width * 3)
- Dim c As Double = ScreenBmp.Width * (r Mod 1)
- If r Mod 1 >= 0.5 Then r -= 1
- rct.X = CInt(c)
- rct.Y = CInt(r)
- rct.Width = bmpMatch.Width
- rct.Height = bmpMatch.Height
- Exit For
- End If
- Next
- logerrors("Geht noch 20")
- bmpMatch.UnlockBits(ImgBmd)
- ScreenBmp.UnlockBits(ScreenBmd)
- ScreenBmp.Dispose()
- Return rct
- End Function
Fazit: Er kommt bis "Geht noch 15"..
Habt ihr eine Idee warum? Er hat nichts anders gemacht als ich. Was kann ich noch zum Debuggen tun, ohne VS zu verwenden?
Vielen Dank im Voraus..
Mit freundlichen Grüßen,
xored
EDIT: Wenn ich die For-Schleifen in einen Try-Block packe, kommt natürlich kein Fehler mehr, er sagt aber natürlich, er habe den Button nicht gefunden..
*Topic verschoben*
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Marcus Gräfe“ ()