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.
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);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…