resizing image on thread instead of ui thread
This commit is contained in:
32
main.go
32
main.go
@@ -29,16 +29,17 @@ type incomingImage struct {
|
||||
}
|
||||
|
||||
type Animation struct {
|
||||
ctx *gg.Context
|
||||
position image.Point
|
||||
dir image.Point
|
||||
height int
|
||||
width int
|
||||
stroke int
|
||||
image []image.Image
|
||||
updown int
|
||||
mqmsg chan mqtt.Message
|
||||
msg string
|
||||
ctx *gg.Context
|
||||
position image.Point
|
||||
dir image.Point
|
||||
height int
|
||||
width int
|
||||
stroke int
|
||||
image []image.Image
|
||||
updown int
|
||||
mqmsg chan mqtt.Message
|
||||
msg string
|
||||
|
||||
countDown int
|
||||
}
|
||||
|
||||
@@ -140,6 +141,12 @@ func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation {
|
||||
}
|
||||
}
|
||||
|
||||
func appendImage(img string, a *Animation) {
|
||||
baseImage, _ := b64.StdEncoding.DecodeString(img)
|
||||
bigImage, _, _ := image.Decode(bytes.NewReader(baseImage))
|
||||
a.image = append(a.image, imaging.Resize(bigImage, 32, 32, imaging.Lanczos))
|
||||
}
|
||||
|
||||
// what happens each frame, at an interval of 50 milliseconds
|
||||
func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
|
||||
incoming := incomingImage{}
|
||||
@@ -168,10 +175,7 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
|
||||
a.msg = string(msg.Payload())
|
||||
a.ctx.DrawString(a.msg, 5, 9)
|
||||
} else {
|
||||
baseImage, _ := b64.StdEncoding.DecodeString(incoming.Image)
|
||||
bigImage, _, _ := image.Decode(bytes.NewReader(baseImage))
|
||||
a.image = append(a.image, imaging.Resize(bigImage, 32, 32, imaging.Lanczos))
|
||||
a.ctx.DrawImageAnchored(a.image[2], 0, 0, 0, 0)
|
||||
go appendImage(incoming.Image, a)
|
||||
}
|
||||
default:
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user