Skip to content

Instantly share code, notes, and snippets.

@zeisss
Created February 19, 2013 15:59
Show Gist options
  • Save zeisss/4987149 to your computer and use it in GitHub Desktop.
Save zeisss/4987149 to your computer and use it in GitHub Desktop.
Create a simple png file with fancy colors
package main
import (
"fmt"
"os"
"image"
"image/png"
"image/color"
)
func paintImage(img *image.RGBA) {
for x := 0; x < 200; x++ {
for y := 0; y < 200; y++ {
img.Set(x, y, color.RGBA{128, uint8(255 - x), uint8(y), 255})
}
}
}
func main() {
var i *image.RGBA
i = image.NewRGBA(image.Rect(0,0, 200, 200))
paintImage(i)
file, ferr := os.OpenFile("test.png", os.O_TRUNC | os.O_CREATE | os.O_WRONLY, 0666)
fmt.Println(ferr);
err := png.Encode(file, i)
file.Sync()
fmt.Println(err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment