Golang image.Paletted.SubImage function example

package image

 func (p *Paletted) SubImage(r Rectangle) Image
  

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.

Golang image.Paletted.SubImage function usage example

 package main

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


 func main() {

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

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

 paletted := image.NewPaletted(rect, p)

 subimg := paletted.SubImage(image.Rect(0, 0, 50, 50))

 fmt.Println(subimg.Bounds())

 }

Output :

(0,0)-(50,50)

Reference :

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

Advertisement