android:动画颜色从颜色到颜色的变化 [英] android: Animate color change from color to color
问题描述
假设我有两种颜色,我需要创建一个实时动画来快速从一种颜色切换到另一种颜色.
Assuming I have two colors, and I need to create a real time animation that fastly switches from a color to another.
我尝试只增加十六进制颜色,直到到达另一个,但这给出了一个非常糟糕的动画,因为它显示了许多不相关的颜色.
I tried just to increment the color hexadecimal until I reach the other, but that gave a really bad animation as it showed lots of unrelated colors.
我正在使用 setColorFilter(color, colorfilter)
来更改图像视图的颜色.
I am using setColorFilter(color, colorfilter)
to change the color of an imageview.
改变色调会给我最好的视觉效果吗?如果是这样,我该如何将其更改为纯色?
Changing the HUE will give me the best visual results? If so, how can I change it for a solid color?
解决方案:我通过递归变换色调解决了
SOLUTION: I solved it by recursively shifting hue
private int hueChange(int c,int deg){
float[] hsv = new float[3]; //array to store HSV values
Color.colorToHSV(c,hsv); //get original HSV values of pixel
hsv[0]=hsv[0]+deg; //add the shift to the HUE of HSV array
hsv[0]=hsv[0]%360; //confines hue to values:[0,360]
return Color.HSVToColor(Color.alpha(c),hsv);
}
推荐答案
SOLUTION: 我通过递归变换色调解决了
SOLUTION: I solved it by recursively shifting hue
private int hueChange(int c,int deg){
float[] hsv = new float[3]; //array to store HSV values
Color.colorToHSV(c,hsv); //get original HSV values of pixel
hsv[0]=hsv[0]+deg; //add the shift to the HUE of HSV array
hsv[0]=hsv[0]%360; //confines hue to values:[0,360]
return Color.HSVToColor(Color.alpha(c),hsv);
}
这篇关于android:动画颜色从颜色到颜色的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!