mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-15 22:48:16 +08:00
重写controller部分,修改search界面,添加歌词滚动效果,部分资源添加到bundle,修复拖动进度条时产生的噪音
This commit is contained in:
56
gui/gutil/resize.go
Normal file
56
gui/gutil/resize.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package gutil
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/model"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/storage"
|
||||
"github.com/nfnt/resize"
|
||||
"image"
|
||||
"image/png"
|
||||
)
|
||||
|
||||
func ResizeImage(resource fyne.Resource, width int, height int) fyne.Resource {
|
||||
data := resource.Content()
|
||||
img, _, err := image.Decode(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return resource
|
||||
}
|
||||
img = resize.Thumbnail(uint(width), uint(height), img, resize.Lanczos3)
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
err = png.Encode(buf, img)
|
||||
if err != nil {
|
||||
return resource
|
||||
}
|
||||
return fyne.NewStaticResource(resource.Name(), buf.Bytes())
|
||||
}
|
||||
|
||||
func NewImageFromPlayerPicture(picture model.Picture) (*canvas.Image, error) {
|
||||
var img *canvas.Image
|
||||
if picture.Data != nil {
|
||||
img = canvas.NewImageFromReader(bytes.NewReader(picture.Data), "cover")
|
||||
// return an error when img is nil
|
||||
if img == nil {
|
||||
return nil, errors.New("fail to read image")
|
||||
}
|
||||
|
||||
} else {
|
||||
uri, err := storage.ParseURI(picture.Url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if uri == nil {
|
||||
return nil, errors.New("fail to fail url")
|
||||
}
|
||||
img = canvas.NewImageFromURI(uri)
|
||||
if img == nil {
|
||||
// bug fix, return a new error to indicate fail to read an image
|
||||
return nil, errors.New("fail to read image")
|
||||
}
|
||||
}
|
||||
// compress image, so it won't be too large
|
||||
img.Resource = ResizeImage(img.Resource, 128, 128)
|
||||
return img, nil
|
||||
}
|
||||
Reference in New Issue
Block a user