Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Count Number of Unique Colors in an Image

, 19 Feb 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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
 
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)

Share

About the Author

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

Comments and Discussions

 
GeneralGood point, Phil! PinmemberDrABELL22-Feb-11 17:54 
GeneralThe big reason the original is better is that the List<>.Con... PinmemberPhil Atkin22-Feb-11 3:41 
GeneralYes it's an alternative, but I think mine is better because ... PinmvpJohn Simmons / outlaw programmer19-Feb-11 7:46 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141220.1 | Last Updated 19 Feb 2011
Article Copyright 2011 by a_pess
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid