How to load ImageButton from embed.FS
I have tried loading images from embed.FS but end up with black square instead of an image.
Images do not show up even after exact resize to 32x32 or trying to cache them into variables.
```go
import (
"embed"
"bytes"
"image"
"image/png"
g "github.com/AllenDang/giu"
)
//go:embed images/*
var imageFS embed.FS
func loadIcon(name string) *image.RGBA {
data, _ := imageFS.ReadFile(name)
img, _, _ := image.Decode(bytes.NewReader(data))
rgba := g.ImageToRgba(img)
return rgba
}
func loop() {
icon1 := loadIcon("images/icon1.png")
icon2 := loadIcon("images/icon2.png")
g.SingleWindow().Layout(
g.Row(
g.ImageButtonWithRgba(icon1).Size(32, 32).OnClick(func() { /*...*/ }),
g.ImageButtonWithRgba(icon2).Size(32, 32).OnClick(func() { /*...*/ }),
),
)
}
```
关闭于 2025-08-03 7 条评论