Golang image.Paletted.Set and SetColorIndex functions example

package image

Golang image.Paletted.Set and SetColorIndex functions usage example

 package main

 import (
 "image"
 "image/color"
 "math/rand"
 )


 func main() {

 p := color.Palette{color.NRGBA{0xf0, 0xf0, 0xf0, 0xff}}

 rect := image.Rect(0, 0, 100, 100)

 paletted := image.NewPaletted(rect, p)

 paletted.Set(10,10, color.RGBA{0, 0, 0, 255}) // black for example

 colorIndex := uint8(rand.Int())

 paletted.SetColorIndex(10, 10, colorIndex)
 }

References :

http://golang.org/pkg/image/#Paletted.Set

http://golang.org/pkg/image/#Paletted.SetColorIndex

Advertisement