Golang image.Alpha.At function examples
package image
func (p *Alpha) At(x, y int) color.Color
Golang image.Alpha.At function usage examples
Example 1:
package main
import (
"fmt"
"image"
"image/jpeg"
"os"
)
func init() {
// damn important or else At(), Bounds() functions will
// caused memory pointer error!!
image.RegisterFormat("jpeg", "jpeg", jpeg.Decode, jpeg.DecodeConfig)
}
func main() {
imgfile, err := os.Open("./img.jpg")
if err != nil {
fmt.Println("img.jpg file not found!")
os.Exit(1)
}
defer imgfile.Close()
img, _, err := image.Decode(imgfile)
fmt.Println(img.At(10, 10)) // <-- here
}
Output :
{255 128 128}
Example 2:
img := image.NewAlpha(image.Rect(-1, -2, 3, 4))
c := color.NRGBAModel.Convert(img.At(x, y)).(color.NRGBA)
Reference :
Advertisement
Something interesting
Tutorials
+6.5k Unix/Linux : How to get own IP address ?
+29.7k Golang : Record voice(audio) from microphone to .WAV file
+12.1k Golang : md5 hash of a string
+10.9k Golang : Get UDP client IP address and differentiate clients by port number
+11.1k Golang : Simple image viewer with Go-GTK
+16.3k Golang :Trim white spaces from a string
+12.2k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+7.7k Golang : Error reading timestamp with GORM or SQL driver
+25.4k Golang : Convert long hexadecimal with strconv.ParseUint example
+7.7k Golang : How to execute code at certain day, hour and minute?
+15.2k Golang : Get HTTP protocol version example
+7.1k Golang : Gorrila mux.Vars() function example