Code:
AnalyseImage("[image path]")
Sub AnalyseImage(ByVal imgPath As String)
Dim bm As Bitmap = Image.FromFile(imgPath)
Dim cols As New Hashtable
Dim item As New System.Collections.DictionaryEntry
Dim wid As Integer = bm.Width
Dim hgt As Integer = bm.Height
Dim totalPixels As Integer = Math.BigMul(wid, hgt)
Dim bFound As Boolean = False
For x As Integer = 0 To wid - 1
For y As Integer = 0 To hgt - 1
Dim tempcolor As Color = bm.GetPixel(x, y)
For Each item In cols
If item.Key.ToString = tempcolor.ToString Then
bFound = True
Exit For
End If
Next
If bFound Then
'//increment pixel count
cols.Item(tempcolor.ToString) = cols.Item(tempcolor.ToString) + 1
Else
'//add color to collection
cols.Add(tempcolor.ToString, 1)
End If
Next
Next
'//we have all the data, so for each color get %
For Each item In cols
Dim sKey As String = item.Key.ToString
Dim iNo As Integer = item.Value
Dim percent As String = FormatPercent(iNo / totalPixels, 2, TriState.True).ToString
Debug.Print("color: " & sKey & " - " & percent)
Next
End Sub