Click here to Skip to main content
15,885,309 members
Articles / Desktop Programming / Windows Forms
Alternative
Tip/Trick

Count Number of Unique Colors in an Image

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
19 Feb 2011CPOL 12K   3
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
Egypt Egypt
Oil & Gas Engineer
C# & VB.net
Coding For Fun Only

Comments and Discussions

 
GeneralGood point, Phil! Pin
DrABELL22-Feb-11 16:54
DrABELL22-Feb-11 16:54 
GeneralThe big reason the original is better is that the List<>.Con... Pin
Phil Atkin22-Feb-11 2:41
Phil Atkin22-Feb-11 2:41 
GeneralYes it's an alternative, but I think mine is better because ... Pin
#realJSOP19-Feb-11 6:46
mve#realJSOP19-Feb-11 6:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.