android开发两种颜色混合计算方法


//ratio比例传递 0.5 就是两种颜色叠加混合的结果,也可以根据自己的需求调整比例
public static int mixColor(int color1, int color2, float ratio) {
	final float inverse = 1 - ratio;
	float a = (color1 >>> 24) * inverse + (color2 >>> 24) * ratio;
	float r = ((color1 >> 16) & 0xFF) * inverse + ((color2 >> 16) & 0xFF) * ratio;
	float g = ((color1 >> 8) & 0xFF) * inverse + ((color2 >> 8) & 0xFF) * ratio;
	float b = (color1 & 0xFF) * inverse + (color2 & 0xFF) * ratio;
	return ((int) a << 24) | ((int) r << 16) | ((int) g << 8) | (int) b;
}

发现SDK里的androidx.core.graphics.ColorUtils类有个方法blendARGB就可以直接实现,干嘛知道的那么少,哈哈哈。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM