2

I'm writing a simple application, which basicly loads some pictures and just shows them to the user. The problem is, when I initialize a vertical image which is taken by my phone, it doesn't recognize that the image is vertical and just swaps the width and height.

Otherwise if I load a vertical image, which is for example downloaded from the internet everything works just fine.

Here you see my application and two loaded pictures. The left one is a downloade one and is displayed vertical. But the right one which was taken with my phone isn't displayed vertically.

Here is my Class/Code:

import javafx.scene.CacheHint;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

public class Picture {
    String name;
    String path;
    String res;
    String size;
    ImageView iv;
    Image image;

    public Picture(String name, String path) {
        this.image = new Image("file:" + path);
        this.name = name;
        this.path = path;
        this.res = image.getWidth() + " x " + image.getHeight();

        this.iv = new ImageView(image);
        this.iv.setFitHeight(180);
        this.iv.setFitWidth(180);
        this.iv.setPreserveRatio(true);
        this.iv.setCache(true);
        this.iv.setCacheHint(CacheHint.SPEED);
        this.iv.setStyle("-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.8), 10, 0, 0, 0);");
    }
}

That's my first question so don't blame me for the layout ;)

Any feedback to my code or question is appreciated. If you need the whole code, just let me know.

Thanks for your help

Umer Farooq
  • 762
  • 1
  • 8
  • 17
Tobyres
  • 21
  • 1
  • 1
    I've not heard/encountered javafx turning an image. I'm pretty sure the image is displayed the way it's saved in the file system. Does it display differently in a image viewer/editor? If not how should your app tell turned images appart from regular ones? – fabian May 10 '18 at 18:59
  • @fabian - my Iphone SE will sometimes decide that a pic should be horizontal vs vertical and store the info that way. Depending on how it is viewed changes its apparent rotation. For example, in a browser viewing JUST the image will show it correctly, embed it in a web page (forum, etc) and it is sideways. Can/will even progressively load sideways. Always have to open my stuff in the GIMP and assure correct rotation before saving. – ivanivan May 10 '18 at 23:18
  • OP - to follow up on my comment to Fabian, check EXIF data for rotation information - see https://stackoverflow.com/questions/21951892/how-to-determine-and-auto-rotate-images – ivanivan May 10 '18 at 23:19
  • @fabian - The wrong displayed image looks just fine in the normal windows directory but thanks for the reply I will keep looking for a solution – Tobyres May 11 '18 at 18:22
  • @ivanivan - I thought the same with trying it with BufferedImage from swing but I was looking for the cleanest solution so i will keep looking. – Tobyres May 11 '18 at 18:30
  • Did you ever find a fix for this? I've encountered this same issue with a slideshow app I made. Windows image viewer displays the image in the correct orientation. – JonR85 Nov 28 '21 at 03:05

0 Answers0