5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 07:29:56 +08:00
wails/v3/pkg/application/image.go
Travis McLane 18746c7819
V3 alpha linux dbus (#2996)
* [v3 linux/systray] dbus generation

* [v3 linux] systemtray dbus implementation

* [v3] add 'id' for MenuSeparator

This is needed in order to have a unique value for all
menuItem(s) such that the Linux implementation doesn't have to
generate new identifiers.
Allowing the reuse keeps a 1-1 mapping in place without any extra effort.

* [v3 example/systray] add radio group to example

* [v3 linux] stub out ExportStatusNotifierItem callbacks

Can only seem to get the `SecondaryActivate` to fire when doing a
3-finger click!  I was expecting a right-click interaction to trigger it.
2023-10-21 11:39:46 +11:00

38 lines
695 B
Go

package application
import (
"bytes"
"image"
"image/draw"
"image/png"
)
func pngToImage(data []byte) (*image.RGBA, error) {
img, err := png.Decode(bytes.NewReader(data))
if err != nil {
return nil, err
}
bounds := img.Bounds()
rgba := image.NewRGBA(bounds)
draw.Draw(rgba, bounds, img, bounds.Min, draw.Src)
return rgba, nil
}
func ToARGB(img *image.RGBA) (int, int, []byte) {
w, h := img.Bounds().Dx(), img.Bounds().Dy()
data := make([]byte, w*h*4)
i := 0
for y := 0; y < h; y++ {
for x := 0; x < w; x++ {
r, g, b, a := img.At(x, y).RGBA()
data[i] = byte(a)
data[i+1] = byte(r)
data[i+2] = byte(g)
data[i+3] = byte(b)
i += 4
}
}
return w, h, data
}