-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
bugSomething isn't workingSomething isn't working
Milestone
Description
Checklist
- I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
- This issue only relates to a single bug. I will open new issues for any other problems.
Describe the bug
Following up on the suggestion from Discord to report this here... If i take the following code:
width := 1024
height := 758
myCanvas := playground.NewSoftwareCanvas()
clockText := canvas.NewText(time.Now().Format("15:04:05"), color.White)
clockText.TextSize = 150
clockText.Alignment = fyne.TextAlignCenter
clockContainer := container.NewCenter(clockText)
myCanvas.SetContent(clockContainer)
myCanvas.Resize(fyne.Size{Width: width, Height: height})
img := myCanvas.Capture()And save the result as an image, I get the expected result:
But if I move myCanvas.Resize(fyne.Size{Width: width, Height: height}) directly after myCanvas := playground.NewSoftwareCanvas(), the result will be wrong:
How to reproduce
- Copy my provided example code
go run .- See that the resulting
clock.pnghas the wrong resolution, it should be 1024x758. - Put
myCanvas.Resize(fyne.Size{Width: width, Height: height})undermyCanvas.SetContent(clockContainer). - Notice that the image is rendered properly.
Screenshots
No response
Example code
package main
import (
"fmt"
"image"
"image/color"
"image/png"
"os"
"time"
"fyne.io/fyne"
"fyne.io/fyne/canvas"
"fyne.io/fyne/container"
"fyne.io/fyne/tools/playground"
)
func main() {
width := 1024
height := 758
myCanvas := playground.NewSoftwareCanvas()
myCanvas.Resize(fyne.Size{Width: width, Height: height})
clockText := canvas.NewText(time.Now().Format("15:04:05"), color.White)
clockText.TextSize = 150
clockText.Alignment = fyne.TextAlignCenter
clockContainer := container.NewCenter(clockText)
myCanvas.SetContent(clockContainer)
img := myCanvas.Capture()
saveImage(img, "clock.png")
}
func saveImage(img image.Image, filename string) {
f, err := os.Create(filename)
if err != nil {
fmt.Println(err)
return
}
defer f.Close()
err = png.Encode(f, img)
if err != nil {
fmt.Println(err)
return
}
}Fyne version
v2.5.4
Go compiler version
1.24.0
Operating system and version
Arch Linux amd64
Additional Information
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working

