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 }