阅读背景:

java 十六进制过度颜色值计算

来源:互联网 

有时候开发ui时要有过渡颜色,就要计算颜色从一个值到另一个值:

代码:

package cyy.demo;

public class Test {

	public static void main(String[] args) {  
		  
	    for (int i = 0; i < 101; i++) {  
	        System.out.println(Integer.toHexString(evaluate(i / 100f, 0xFFFFFFFF, 0x00000000)));  
	    }  
	}  
	  
	private static Integer evaluate(float fraction, Integer startValue, Integer endValue) {  
	    int startInt = startValue;  
	    int startA = (startInt >> 24) & 0xff;  
	    int startR = (startInt >> 16) & 0xff;  
	    int startG = (startInt >> 8) & 0xff;  
	    int startB = startInt & 0xff;  
	    int endInt = (Integer) endValue;  
	    int endA = (endInt >> 24) & 0xff;  
	    int endR = (endInt >> 16) & 0xff;  
	    int endG = (endInt >> 8) & 0xff;  
	    int endB = endInt & 0xff;  
	    return (int) ((startA + (int) (fraction * (endA - startA))) << 24)  
	            | (int) ((startR + (int) (fraction * (endR - startR))) << 16)  
	            | (int) ((startG + (int) (fraction * (endG - startG))) << 8)  
	            | (int) ((startB + (int) (fraction * (endB - startB))));  
	}
}
pack



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: