Skip to content

Instantly share code, notes, and snippets.

@Tnze
Last active September 8, 2019 02:49
Show Gist options
  • Save Tnze/14fda4cc41747f3486f57fcfa53d882b to your computer and use it in GitHub Desktop.
Save Tnze/14fda4cc41747f3486f57fcfa53d882b to your computer and use it in GitHub Desktop.
颜色表取图片
package main
import (
"fmt"
"image"
"image/color"
"image/png"
"os"
)
func main() {
w, h := 503, 122
img := image.NewRGBA(image.Rect(0, 0, w, h))
for i := 0; i < w; i++ {
for j := 0; j < h; j++ {
var r, g, b uint8
_, err := fmt.Scanf("%d,%d,%d\n", &r, &g, &b)
if err != nil {
panic(err)
}
img.Set(i, j, color.RGBA{r, g, b, 255})
}
}
f, err := os.Create("image.png")
if err != nil {
panic(err)
}
if err := png.Encode(f, img); err != nil {
f.Close()
panic(err)
}
if err := f.Close(); err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment