Skip to content

Instantly share code, notes, and snippets.

@neetsdkasu
Created September 26, 2019 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neetsdkasu/f58f5c30360bdd6aac9468aee576a0ba to your computer and use it in GitHub Desktop.
Save neetsdkasu/f58f5c30360bdd6aac9468aee576a0ba to your computer and use it in GitHub Desktop.
Goでpng生成を試してみた
package main
import (
"image"
"image/color/palette"
"image/png"
"os"
)
func main() {
img := image.NewRGBA(image.Rect(0, 0, 512, 512))
for y := 0; y < 512; y++ {
for x := 0; x < 512; x++ {
img.Set(x, y, palette.Plan9[y/2])
}
}
file, err := os.Create("foo.png")
if err != nil {
panic(err)
}
defer file.Close()
err = png.Encode(file, img)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment