tins2020/img/io.go
Sander Schobers cd5ca3f04f Added tool to color image.
Separated some image related methods.
Added feedback for simulation speed (colored buttons).
2020-05-10 17:40:56 +02:00

30 lines
437 B
Go

package img
import (
"image"
"image/png"
"os"
)
func EncodePNG(path string, im image.Image) error {
dst, err := os.Create(path)
if err != nil {
return err
}
defer dst.Close()
return png.Encode(dst, im)
}
func DecodeImage(path string) (image.Image, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
im, _, err := image.Decode(f)
if err != nil {
return nil, err
}
return im, nil
}