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就可以直接实现,干嘛知道的那么少,哈哈哈。

原文地址:https://www.cnblogs.com/yongfengnice/p/14690473.html