-
Notifications
You must be signed in to change notification settings - Fork 4
/
empty_image.go
51 lines (42 loc) · 1.04 KB
/
empty_image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Padesátá šestá část
// Programovací jazyk Go a assembler (3.část)
// https://www.root.cz/clanky/programovaci-jazyk-go-a-assembler-3-cast/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů z padesáté šesté části:
// https://github.com/tisnik/go-root/blob/master/article_56/README.md
package main
import (
"image"
"image/png"
"log"
"os"
)
const DestinationImageFileName = "empty.png"
func saveImage(filename string, img image.Image) error {
outfile, err := os.Create(filename)
if err != nil {
return err
}
defer outfile.Close()
png.Encode(outfile, img)
return nil
}
func fillPixels(pixels []uint8) {
for i := 0; i < len(pixels); i++ {
pixels[i] = 255
}
}
func main() {
destinationImage := image.NewRGBA(image.Rect(0, 0, 256, 256))
fillPixels(destinationImage.Pix)
err := saveImage(DestinationImageFileName, destinationImage)
if err != nil {
log.Fatal(err)
}
}