golang-二维数组转图片
import "image"
img := image.NewGray(image.Rect(0, 0, len(array[0]), len(array)))
for y, row := range array {
for x, gray := range row {
img.Set(x, y, color.Gray{Y: uint8(gray)})
}
}
// 将图片保存为JPEG格式的文件
outFile, _ := os.Create("output.png")
err = jpeg.Encode(outFile, img, &jpeg.Options{Quality: 100})
if err != nil {
log.Error(err)
}
outFile.Close()