是否可以在javafx中制作图像饱和度动画?

问题描述 投票:2回答:1

例如,我有这样的东西

ImageView img = new ImageView();
img.setImage(new Image("someimg.png"));
ColorAdjust ca = new ColorAdjust();
ca.setSaturation(0.5);
img.setEffect(ca)

我希望饱和度随时间平滑增加。有没有办法做到这一点,例如使用时间轴对象?

javafx
1个回答
3
投票

我找到了解决方法

    ImageView img = new ImageView();
    img.setImage(new Image("someimg.png"));

    ColorAdjust ca = new ColorAdjust();
    img.setEffect(ca);

    Timeline t = new Timeline(
            new KeyFrame(Duration.ZERO, new KeyValue(ca.saturationProperty(), -1.0)),
            new KeyFrame(Duration.seconds(5), new KeyValue(ca.saturationProperty(), 1.0))
    );

    t.play();
© www.soinside.com 2019 - 2024. All rights reserved.