Created
September 13, 2011 03:38
-
-
Save skoji/1213072 to your computer and use it in GitHub Desktop.
GDD2011JP DevQuiz Go!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"strings" | |
"image/png" | |
) | |
func CountColor(pngdata io.Reader) int { | |
colors := make(map[string] bool) | |
img,_:= png.Decode(pngdata) | |
x, y := img.Bounds().Max.X, img.Bounds().Max.Y | |
for i := 0; i < x; i++ { | |
for j:= 0; j < y; j++ { | |
r,g,b,_ := img.At(i,j).RGBA() | |
index := fmt.Sprintf("%x%x%x",r,g,b) | |
colors[index] = true | |
} | |
} | |
return len(colors) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment