Golang image.Alpha16.SubImage example
package image
func (p *Alpha16) 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.Alpha16.SubImage usage example
package main
import (
"fmt"
"image"
"image/png"
"os"
)
func init() {
// without this register .. At(), Bounds() functions will
// caused memory pointer error!!
image.RegisterFormat("png", "png", png.Decode, png.DecodeConfig)
}
func main() {
imgfile, err := os.Open("./img.png")
if err != nil {
fmt.Println("img.png file not found!")
os.Exit(1)
}
defer imgfile.Close()
img, _, err := image.Decode(imgfile)
bounds := img.Bounds()
alpha16 := image.NewAlpha16(bounds)
rect := image.Rect(0, 0, 100, 100)
subimg := alpha16.SubImage(rect)
fmt.Println(subimg.Bounds())
fmt.Println(subimg.At(10, 10))
}
Reference :
Advertisement
Something interesting
Tutorials
+5.4k Golang : Reclaim memory occupied by make() example
+10.3k Golang : Wait and sync.WaitGroup example
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+25.6k Golang : convert rune to integer value
+10.7k Golang : Get currencies exchange rates example
+13.6k Golang : Query string with space symbol %20 in between
+6.3k Golang : Selection sort example
+13.8k Golang : Convert spaces to tabs and back to spaces example
+12.7k Golang : zlib compress file example
+7.6k Javascript : Push notifications to browser with Push.js
+10.4k Golang : Generate random integer or float number
+16.6k Golang : Delete files by extension