PDA

View Full Version : [.net]FindColorSpiral



SlashShot
12-23-2007, 04:50 PM
credits to to cruel from www.cruels.net, i just converted it to vb.net, this also uses a picture, instead of the traditional getPixel thing, so u may be able to customize this for findBitmap. I may do that later on, and i will post the source if i get it to work.

Function FindColorSpiral(ByVal color As Color, ByVal StartPoint As Point, ByVal Area As Rectangle) As Point
Dim AreaSize As Size = Area.Size
Dim TempBitmap As New Bitmap(AreaSize.Width, AreaSize.Height)
Graphics.FromImage(TempBitmap).CopyFromScreen(Area .Location, New Point(), AreaSize)
Dim x As Integer = StartPoint.X - Area.X
Dim y As Integer = StartPoint.Y - Area.Y
Dim direction, length, i As Integer
direction = 0 : length = 1
If color = TempBitmap.GetPixel(x, y) Then Return New Point(Area.X + x, Area.Y + y)
Do Until (x < 2) Or (y < 2) Or (x > Area.Width - 2) Or (y > Area.Height - 2)
For i = 1 To length
Select Case direction
Case 0 : y = y - 1
Case 1 : x = x + 1
Case 2 : y = y + 1
Case 3 : x = x - 1
End Select
If color = TempBitmap.GetPixel(x, y) Then Return New Point(Area.X + x, Area.Y + y)
Next i
direction = (direction + 1) Mod 4
If (direction Mod 2) = 0 Then length = length + 1
Loop
Return New Point(-1, -1)
End Function