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
+12.2k Golang : List running EC2 instances and descriptions
+11.9k Golang : Convert decimal number(integer) to IPv4 address
+4.8k PHP : Extract part of a string starting from the middle
+27.4k Golang : Convert CSV data to JSON format and save to file
+12.5k Golang : HTTP response JSON encoded data
+18.8k Golang : Delete duplicate items from a slice/array
+24.5k Golang : Change file read or write permission example
+17.2k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+5.9k Golang : Use NLP to get sentences for each paragraph example
+6.4k PHP : Proper way to get UTF-8 character or string length
+10.4k Golang : Meaning of omitempty in struct's field tag
+9.6k Golang : Copy map(hash table) example