Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image with ImageFillContain seen stretched before correcting for aspect. #1266

Closed
datboy-design opened this issue Aug 27, 2020 · 3 comments
Closed
Labels
bug Something isn't working Hacktoberfest

Comments

@datboy-design
Copy link

Describe the bug:

Image first shows as stretched to fill canvas. After a short pause (probably processing time) the image is re-displayed corrected for aspect.

To Reproduce:

Run this code with local image

package main

import (
"fmt"
"imaging"
"os"

"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/canvas"

)

func main() {
myApp := app.New()
w := myApp.NewWindow("Image")
w.Resize(fyne.NewSize(600, 600)) // problem for all sizes tried

// Open JPEG file and get io.Reader

fileName := os.Args[1]
file, err := os.Open(fileName)
if err != nil {
	fmt.Printf("Error opening file %s\n", fileName)
	return
}

// Set the AutroOrientation option for decoding.
// We need to use imaging,Decode because it checks for and corrects for orientation data.
// If present this is held in an EXIF tag. image.Decode() follows the standard
// JPEG library and assumes file will be soley JFIF and correctly orientated.
    // Using imaging package to get round this.

opt := imaging.AutoOrientation(true)  // create option for imaging.Decode()
img, err := imaging.Decode(file, opt) // decoded file as image.Image

if err != nil {
	fmt.Printf("Error decoding image %s\nError %v\n", fileName, err)
	return
}

image := canvas.NewImageFromImage(img)
image.FillMode = canvas.ImageFillContain
w.SetContent(image)
w.ShowAndRun()

}

Screenshots:

Device (please complete the following information):

  • OS: "Linux Ubuntu"
  • Version: "18.04.5 LTS (Bionic Beaver)"
  • Go version: "go1.15 linux/amd64"
  • Fyne version: "v1.3.3-3-g6c9ed1b5"]
@andydotxyz andydotxyz added the bug Something isn't working label Aug 27, 2020
@andydotxyz andydotxyz added this to the 1.3.x milestone Aug 27, 2020
@andydotxyz andydotxyz changed the title Image Display - Image seen stretched before correcting for aspect. Image with ImageFillContain seen stretched before correcting for aspect. Oct 20, 2020
andydotxyz added a commit to andydotxyz/fyne that referenced this issue Oct 20, 2020
Issue was that we were reading aspect before setting it on the first frame.
Fixes fyne-io#1266
andydotxyz added a commit that referenced this issue Oct 20, 2020
Issue was that we were reading aspect before setting it on the first frame.
Fixes #1266
@andydotxyz
Copy link
Member

On develop for testing.

@stuartmscott
Copy link
Member

I can still reproduce. Run the below with any jpeg image as go run main.go /path/to/image.jpg

package main

import (
	"bytes"
	"fyne.io/fyne"
	"fyne.io/fyne/app"
	"fyne.io/fyne/canvas"
	"fyne.io/fyne/widget"
	"image/jpeg"
	"io/ioutil"
	"log"
	"os"
)

func main() {
	// Create Fyne App
	a := app.New()

	// Create Fyne Window
	w := a.NewWindow("Image Jump")

	// Create image to hold image
	img := &canvas.Image{
		FillMode: canvas.ImageFillOriginal,
	}
	scroller := widget.NewScrollContainer(img)

	// Create goroutine to load file contents and update image
	go func() {
		data, err := ioutil.ReadFile(os.Args[1])
		if err != nil {
			log.Println("Error:", err)
			return
		}
		i, err := jpeg.Decode(bytes.NewReader(data))
		if err != nil {
			log.Println("Error:", err)
			return
		}
		img.Image = i
		img.Refresh()
		scroller.Refresh()
	}()

	// Add scroller to window
	w.SetContent(scroller)

	w.Resize(fyne.NewSize(480, 600))
	w.ShowAndRun()
}

@stuartmscott stuartmscott reopened this Oct 20, 2020
@stuartmscott
Copy link
Member

Oops, I just noticed I'm using ImageFillOriginal and this issue is about ImageFillContain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Hacktoberfest
Projects
None yet
Development

No branches or pull requests

3 participants