Golang image.Alpha.ColorModel function example
package image
func (p *Alpha) ColorModel() color.Model
Golang image.Alpha.ColorModel function usage example ( taken from http://golang.org/src/pkg/image/image_test.go )
func cmp(t *testing.T, cm color.Model, c0, c1 color.Color) bool {
r0, g0, b0, a0 := cm.Convert(c0).RGBA()
r1, g1, b1, a1 := cm.Convert(c1).RGBA()
return r0 == r1 && g0 == g1 && b0 == b1 && a0 == a1
}
testImage := []image{
NewRGBA(Rect(0, 0, 10, 10)),
NewRGBA64(Rect(0, 0, 10, 10)),
NewNRGBA(Rect(0, 0, 10, 10)),
NewNRGBA64(Rect(0, 0, 10, 10)),
NewAlpha(Rect(0, 0, 10, 10)),
NewAlpha16(Rect(0, 0, 10, 10)),
NewGray(Rect(0, 0, 10, 10)),
NewGray16(Rect(0, 0, 10, 10)),
NewPaletted(Rect(0, 0, 10, 10), color.Palette{
Transparent,
Opaque,
}),
}
for _, m := range testImage {
if !cmp(t, m.ColorModel(), Transparent, m.At(6, 3)) {
t.Errorf("%T: at (6, 3), want a zero color, got %v", m, m.At(6, 3))
continue
}
References :
Advertisement
Something interesting
Tutorials
+6.5k Elasticsearch : Shutdown a local node
+13k Golang : Get terminal width and height example
+10.9k Golang : Create Temporary File
+16k Golang : Generate universally unique identifier(UUID) example
+6.3k Golang : Selection sort example
+20.2k Golang : Count number of digits from given integer value
+14k Golang : Google Drive API upload and rename example
+22.7k Golang : Strings to lowercase and uppercase example
+14.4k Golang : On enumeration
+13.6k Golang : Strings comparison
+15k Golang : Search folders for file recursively with wildcard support
+6.9k Golang : How to setup a disk space used monitoring service with Telegram bot