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
+37.5k Golang : Converting a negative number to positive number
+16.9k Golang : How to generate QR codes?
+8.2k Golang : HttpRouter multiplexer routing example
+14k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+48.5k Golang : Upload file from web browser to server
+5.9k Unix/Linux : How to open tar.gz file ?
+16.3k Golang : How to extract links from web page ?
+11.6k Golang : Display a text file line by line with line number example
+23.5k Golang : Check if element exist in map
+7.1k Golang : Array mapping with Interface
+13.9k Golang : How to check if a file is hidden?