-
-
Save neetsdkasu/f58f5c30360bdd6aac9468aee576a0ba to your computer and use it in GitHub Desktop.
Goでpng生成を試してみた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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