Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Drawing
- Module ImageColorCounter
- Sub Main()
- If My.Application.CommandLineArgs.Count > 0 Then
- Dim img As Bitmap
- Try
- img = New Bitmap(My.Application.CommandLineArgs(0))
- Catch ex As Exception
- Console.WriteLine("Failed to load Image:" & vbCrLf & My.Application.CommandLineArgs(0))
- Console.WriteLine("Press Enter")
- Console.ReadLine()
- Exit Sub
- End Try
- Dim ColorDictionary As New Dictionary(Of Color, Integer)
- For y = 0 To img.Height - 1
- For x = 0 To img.Width - 1
- Dim C As Color = img.GetPixel(x, y)
- If ColorDictionary.ContainsKey(C) Then ColorDictionary(C) += 1 Else ColorDictionary.Add(C, 1)
- Next
- Next
- Console.WriteLine("There are " & ColorDictionary.Count & " colors in this image")
- Console.WriteLine("Press C to cancel, Any key to see color table")
- If Console.ReadKey.Key = ConsoleKey.C Then
- Exit Sub
- Else
- Dim I As Integer = 0
- Dim count As Integer = 0
- For Each C As KeyValuePair(Of Color, Integer) In ColorDictionary
- I += 1
- Console.WriteLine(I & vbTab & "[A:" & C.Key.A & vbTab & _
- "R:" & C.Key.R & vbTab & _
- "G:" & C.Key.G & vbTab & _
- "B:" & C.Key.B & vbTab & "] = " & _
- C.Value)
- count += 1
- If count = 256 AndAlso I < ColorDictionary.Count Then
- count = 0
- Console.WriteLine("Press C to cancel, Any key to see color table")
- If Console.ReadKey.Key = ConsoleKey.C Then Exit Sub
- End If
- Next
- Console.WriteLine("Color table completed, Press any key to exit")
- Console.ReadKey()
- End If
- End If
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment