本文介绍了动画图像的饱和度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以对图像(例如png)的饱和度进行动画处理?例如,从灰度到全彩色.另外,如果我可以使用插值器.

Is it possible to animate the saturation of an image (e.g. png) over time? For example from grayscale to full color. Plus if I can use an Interpolator.

我已经看过EffectFactory和ColorMatrix类,但是无法将它们与动画/过渡结合使用.

I have seen the EffectFactory and the ColorMatrix classes but I cannot combine them with an animation/transition.

例如在Drawable drawable上应用灰度饱和度:

E.g. applying grayscale saturation on a Drawable drawable:

ColorMatrix matrix = new ColorMatrix();
matrix.setSaturation(0);

ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
drawable.setColorFilter(filter);

以及稍后完全饱和:

matrix.setSaturation(1);


对于那些对我基于Simon的答案的完整解决方案感兴趣的人


For anyone interested my full solution based on Simon's answer:

final ColorMatrix matrix = new ColorMatrix();
final Drawable drawable = ... ;

ValueAnimator animation = ValueAnimator.ofFloat(0f, 1f);
animation.setDuration(1000);
//   animation.setInterpolator();
animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
        matrix.setSaturation(animation.getAnimatedFraction());
        ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
        drawable.setColorFilter(filter);
    }
});
animation.start();

推荐答案

当然可以使用ValueAnimator实现:

It certainly could be achieved with a ValueAnimator:

ValueAnimator animation = ValueAnimator.ofFloat(0f, 1f);
animation.setDuration(1000);
animation.addUpdateListener(new AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
        matrix.setSaturation(animation.getAnimatedFraction());
    }
});
animation.start();

这篇关于动画图像的饱和度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 08:15