Golang image.NewGray function examples
package image
func NewGray(r Rectangle) *Gray
NewGray returns a new Gray with the given bounds.
Golang image.NewGray function usage examples
Example 1:
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()
newgraycanvas := image.NewGray(bounds)
rect := image.Rect(0, 0, 100, 100)
subimg := newgraycanvas.SubImage(rect)
fmt.Println(subimg.Bounds())
fmt.Println(subimg.At(10, 10))
}
Example 2:
imgRect := image.Rect(0, 0, 200, 200)
img := image.NewGray(imgRect)
References :
Advertisement
Something interesting
Tutorials
+5.7k Golang : Error handling methods
+11.5k Golang : Change date format to yyyy-mm-dd
+13k Golang : Calculate elapsed years or months since a date
+6.6k Golang : Warp text string by number of characters or runes example
+8.6k Golang : Add text to image and get OpenCV's X, Y co-ordinates example
+9.4k Android Studio : Indicate progression with ProgressBar example
+12.5k Golang : HTTP response JSON encoded data
+46.5k Golang : Marshal and unmarshal json.RawMessage struct example
+5.9k Facebook : How to force facebook to scrape latest URL link data?
+23.5k Golang : Check if element exist in map
+12.2k Golang : List running EC2 instances and descriptions
+9.5k Mac OSX : Get a process/daemon status information