import "image" func main() { image := image.NewRGBA(image.Rect(0, 0, 100, 100)) image.SetRGBA(50, 50, color.RGBA{255, 0, 0, 255}) // sets pixel at (50,50) to red }
import ( "image" "image/color" ) func main() { file, _ := os.Open("image.png") defer file.Close() image, _, _ := image.Decode(file) rgbaImage := image.(*image.RGBA) rgbaImage.SetRGBA(50, 50, color.RGBA{255, 0, 0, 255}) // sets pixel at (50,50) to red }In this example, we open an existing PNG image file and decode it into an image object. We then cast the image object into an RGBA image object and set the pixel at (50,50) to red using the SetRGBA method. Package library: "image" package.