0

How do I scale down an image using ScaleTransition? I have this right now and it only scales up. I not if I'm misunderstanding the method, but I have it scaling From 1 to 0.8. For some reason this still scales up.

ScaleTransition st = new ScaleTransition(Duration.millis(900), iv2);
        st.setFromX(1);
        st.setFromY(1);
        st.setByX(0.8);
        st.setByY(0.8);
        st.play();

If I reverse the values like so, it shows up small but snaps bigger and scales up again.

ScaleTransition st = new ScaleTransition(Duration.millis(900), iv2);
        st.setFromX(0.8);
        st.setFromY(0.8);
        st.setByX(1);
        st.setByY(1);
        st.play();

Is there a way I can just get the ScaleTransition to scale down?

Enkrypton
  • 39
  • 1
  • 2
  • 15
  • Try to use third party library like [OpenCV](http://docs.opencv.org/2.4/doc/tutorials/introduction/desktop_java/java_dev_intro.html) and see this [question](https://stackoverflow.com/questions/16497853/scale-a-bufferedimage-the-fastest-and-easiest-way) for more information – Fady Saad Jun 06 '17 at 03:26
  • 2
    Two things you can try. I believe either one will work but I can't test them right now. Either (1) Pass a negative value to `setByX` and `setByY`. Or (2) Instead of `setByX` and `setByY`, use `setToX` and `setToY`. – Dawood ibn Kareem Jun 06 '17 at 03:32
  • Do you mean an Image in an ImageView? If so, javafx doesnt have a that user friendly sizing/scaling mechansim. Which means its propably the best to search for a thirdparty library for this. – n247s Jun 06 '17 at 03:42
  • 1
    If you use `setByX(0.8)` that means you scale up by a factor of `1+0.8=1.8` – fabian Jun 06 '17 at 05:15
  • Negative values seems to do the trick. Thanks – Enkrypton Jun 06 '17 at 20:23

1 Answers1

1
ScaleTransition st = new ScaleTransition(Duration.millis(900), iv2);
        st.setFromX(1);
        st.setFromY(1);
        st.setToX(0.8);
        st.setToY(0.8);
        st.play();

This can scale down, the size of component scale from 100% down to 80%, you can scale up with this code, change 0.8 to a number bigger than 1, sorry my English so bad

yyater97
  • 1,697
  • 2
  • 9
  • 5