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
+5.2k Golang : The Tao of importing package
+21.2k Golang : Get password from console input without echo or masked
+9.3k Golang : How to get username from email address
+8.3k Golang : Configure Apache and NGINX to access your Go service example
+4.4k Linux/MacOSX : Search and delete files by extension
+20.2k Golang : How to get struct tag and use field name to retrieve data?
+14.9k Golang : Submit web forms without browser by http.PostForm example
+26.4k Golang : Convert(cast) string to uint8 type and back to string
+5.5k Golang : Display advertisement images or strings on random order
+8.5k PHP : How to parse ElasticSearch JSON ?
+10.3k Golang : Convert file unix timestamp to UTC time example