
Public Class Form1
Structure WhiteBlock
Dim Width As Integer
Dim Height As Integer
End Structure
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Match = Color.White
Dim Image As Bitmap = pb.Image
Dim Heights As New List(Of Integer)
Dim BlockList As New List(Of WhiteBlock)
Dim CurrentWhiteBlock As New WhiteBlock
For x As Integer = 0 To Image.Width - 1
For y As Integer = 0 To Image.Height - 1
If Image.GetPixel(x, y).ToArgb() = Match.ToArgb() Then
Image.SetPixel(x, y, Color.White)
CurrentWhiteBlock.Width += 1
CurrentWhiteBlock.Height += 1
Else
Image.SetPixel(x, y, Color.Green)
If Not CurrentWhiteBlock.Height = 0 Then
If Not Heights.Contains(CurrentWhiteBlock.Height) Then
Heights.Add(CurrentWhiteBlock.Height)
End If
End If
CurrentWhiteBlock = New WhiteBlock
End If
Next
Next
Dim Largest As Integer = Heights(0)
For Each n As Integer In Heights
If n > Largest Then
Largest = n
End If
Next
lbl.Text = "Height of largest rectangle is: " & Largest
End Sub
End Class
