Sander Schobers
cd5ca3f04f
Separated some image related methods. Added feedback for simulation speed (colored buttons).
28 lines
519 B
Go
28 lines
519 B
Go
package main
|
|
|
|
import (
|
|
"image"
|
|
"image/color"
|
|
|
|
"opslag.de/schobers/tins2020/img"
|
|
)
|
|
|
|
func setAlpha(path string, alpha int) error {
|
|
src, err := img.DecodeImage(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
bounds := src.Bounds()
|
|
dst := image.NewNRGBA(bounds)
|
|
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
|
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
|
c := color.NRGBAModel.Convert(src.At(x, y)).(color.NRGBA)
|
|
if c.A > 0 {
|
|
c.A = uint8(alpha)
|
|
}
|
|
dst.Set(x, y, c)
|
|
}
|
|
}
|
|
return img.EncodePNG(path, dst)
|
|
}
|