import ( "image" "image/color" ) func main() { rgba := image.NewRGBA(image.Rect(0, 0, 100, 200)) // Set first pixel to red rgba.Set(0, 0, color.RGBA{255, 0, 0, 255}) // Set last pixel to green rgba.Set(99, 199, color.RGBA{0, 255, 0, 255}) }
import ( "image" "image/jpeg" "os" ) func main() { reader, err := os.Open("image.jpg") if err != nil { panic(err) } defer reader.Close() img, err := jpeg.Decode(reader) if err != nil { panic(err) } rgba := image.NewRGBA(img.Bounds()) // Convert existing image to RGBA for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ { for x := img.Bounds().Min.X; x < img.Bounds().Max.X; x++ { rgba.Set(x, y, img.At(x, y)) } } }In both examples, the RGBA struct is used to represent an image in memory. The package used is "image" which is part of the standard Go library.