Advertisement
coderail

Pixel Scanner - VB.NET

Nov 24th, 2011
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. '------------------
  2. 'Creator: aeonhack
  3. 'Site: elitevs.net
  4. 'Created: 11/24/2011
  5. 'Changed: 11/24/2011
  6. 'Version: 1.0.1
  7. '------------------
  8. Class ScreenSearch
  9.  
  10. Private G As Graphics
  11. Private B As Bitmap
  12. Private R As Rectangle
  13. Private BD As BitmapData
  14.  
  15. Private X, Y As Integer
  16. Private Row, Column As Integer
  17. Private Count As Integer
  18. Private _GetPoint As Byte()
  19.  
  20. Sub New()
  21. B = New Bitmap(1, 1)
  22. G = Graphics.FromImage(B)
  23. End Sub
  24.  
  25. Sub GetScreen(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  26. B.Dispose()
  27. G.Dispose()
  28.  
  29. R = New Rectangle(0, 0, width, height)
  30. B = New Bitmap(width, height, PixelFormat.Format24bppRgb)
  31. G = Graphics.FromImage(B)
  32.  
  33. G.CopyFromScreen(x, y, 0, 0, R.Size, CopyPixelOperation.SourceCopy)
  34. End Sub
  35.  
  36. Function GetPixel(ByVal x As Integer, ByVal y As Integer) As Color
  37. Return B.GetPixel(x, y)
  38. End Function
  39.  
  40. Function GetPoint(ByVal c As Color, ByVal offset As Integer) As Point
  41. Count = 0
  42.  
  43. BD = B.LockBits(R, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb)
  44. _GetPoint = New Byte((BD.Stride * R.Height) - 1) {}
  45.  
  46. Marshal.Copy(BD.Scan0, _GetPoint, 0, _GetPoint.Length)
  47. B.UnlockBits(BD)
  48.  
  49. For Y = 0 To R.Height - 1
  50. Row = Y * BD.Stride
  51. For X = 0 To R.Width - 1
  52. Column = Row + X * 3
  53. If _GetPoint(Column) = c.B AndAlso _
  54. _GetPoint(Column + 1) = c.G AndAlso _
  55. _GetPoint(Column + 2) = c.R Then
  56.  
  57. If Count = offset Then
  58. Return New Point(X, Y)
  59. Else
  60. Count += 1
  61. End If
  62. End If
  63. Next
  64. Next
  65.  
  66. Return New Point(-1, -1)
  67. End Function
  68.  
  69. Function Contains(ByVal c As Color) As Boolean
  70. Return Not (GetPoint(c, 0).X = -1)
  71. End Function
  72.  
  73. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement