Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Count Number of Unique Colors in an Image

0.00/5 (No votes)
19 Feb 2011 1  
I think we may check if the color is repeated or not, any how this another alternative but in VB.NetPublic Shared Function GetImageColorsCount(ByVal bitmap As Bitmap) As Integer Dim ColorList As New System.Collections.Generic.List(Of Integer) Dim clr As Integer For...
I think we may check if the color is repeated or not, any how this another alternative but in VB.Net

VB
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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here