I think we may check if the color is repeated or not, any how this another alternative but in VB.Net
Public Shared Function GetImageColorsCount(ByVal bitmap As Bitmap) As Integer
Dim ColorList As New System.Collections.Generic.List(Of Integer)
Dim clr As Integer
For y As Integer = 0 To bitmap.Height - 1
For x As Integer = 0 To bitmap.Width - 1
clr = bitmap.GetPixel(x, y).ToArgb()
If Not ColorList.Contains(clr) Then ColorList.Add(clr)
Next
Next
GetImageColorsCount = ColorList.Count
End Function