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