Golang image.Gray.Set and SetGray functions example
package image
func (p *Gray) Set(x, y int, c color.Color)
Golang image.Gray.Set and SetGray functions usage example
package main
import (
"fmt"
"image"
"image/color" // for color.Alpha{a}
"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()
canvas := image.NewGray(bounds) // for Gray
canvas.Set(100, 100, image.Transparent)
// http://golang.org/pkg/image/color/#Gray
// Gray represents an 8-bit grayscale color.
x := 512
y := 512
a := uint8(255)
canvas.SetGray(x, y, color.Gray{a})
}
References :
Advertisement
Something interesting
Tutorials
+5.7k Linux/Unix/PHP : Restart PHP-FPM
+7.4k Golang : Word limiter example
+15.3k Golang : How to get Unix file descriptor for console and file
+17.7k Golang : Read data from config file and assign to variables
+9.1k Golang : Intercept and compare HTTP response code example
+3.7k Golang : Switch Redis database redis.NewClient
+4.9k JQuery : Calling a function inside Jquery(document) block
+19.6k Golang : Set or Add HTTP Request Headers
+4.7k Unix/Linux : How to pipe/save output of a command to file?
+17.6k Convert JSON to CSV in Golang
+7.6k Golang : Convert(cast) io.Reader type to string
+13.9k Golang : Get current time