Golang image.Image type example
package image
Image is a finite rectangular grid of color.Color values taken from a color model.
Golang image.Image type 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()
cmodel := img.ColorModel()
at := img.At(100,100)
fmt.Println(bounds)
fmt.Println(cmodel)
fmt.Println(at)
}
Sample output(depending on input image) :
(0,0)-(600,849)
&{0x7ec10}
{255 255 255 255}
Reference :
Advertisement
Something interesting
Tutorials
+9.4k Golang : Terminate-stay-resident or daemonize your program?
+13.5k Golang : How to get year, month and day?
+14.5k Golang : Rename directory
+12.1k Golang : Save webcamera frames to video file
+19k Golang : Padding data for encryption and un-padding data for decryption
+6k PageSpeed : Clear or flush cache on web server
+6k PHP : How to check if an array is empty ?
+14k Golang : Reverse IP address for reverse DNS lookup example
+12.5k Golang : Forwarding a local port to a remote server example
+11.3k Golang : Post data with url.Values{}
+7.7k Golang : Test if an input is an Armstrong number example
+7k Golang : constant 20013 overflows byte error message