Golang image.Paletted type and NewPaletted function example

package image

Paletted is an in-memory image of uint8 indices into a given palette.

NewPaletted returns a new Paletted with the given width, height and palette.

Golang image.Paletted type and NewPaletted function usage example

 package main

 import (
 "fmt"
 "image"
 "image/color"
 )


 func main() {

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

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

 paletted := image.NewPaletted(rect, p)

 fmt.Println("Pix : ",paletted.Pix)

 fmt.Println("Stride : ", paletted.Stride)

 fmt.Println("Palette : ", paletted.Palette)
 }

Output :

Pix : [0 0 0 ..... 0]

Stride : 100

Palette : [{240 240 240 255}]

References :

http://golang.org/pkg/image/#NewPaletted

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

Advertisement