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
+14.7k Golang : Reset buffer example
+14k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+37.7k Golang : Comparing date or timestamp
+14.4k Golang : How to filter a map's elements for faster lookup
+5.4k Golang : What is StructTag and how to get StructTag's value?
+14k Golang : concatenate(combine) strings
+5.5k Golang : If else example and common mistake
+12.5k Golang : "https://" not allowed in import path
+9.3k Golang : How to get ECDSA curve and parameters data?
+21.1k Golang : Sort and reverse sort a slice of strings
+10.9k Golang : How to transmit update file to client by HTTP request example
+14.3k Golang : Get uploaded file name or access uploaded files