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

相关文章:

  • 2021-06-15
  • 2021-08-16
  • 2021-12-29
  • 2022-12-23
  • 2021-12-03
  • 2021-11-24
  • 2021-07-10
  • 2021-08-16
猜你喜欢
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2021-12-29
  • 2022-01-30
相关资源
相似解决方案