我一直在努力将两个ARGB值结合起来 - 尽管有很多阅读,例如这里...... How to mix two ARGB pixels?
我没有得到我期待的结果 - 或者我所期待的是错误的;如果有人可以提出这样做的功能,那就太好了。
我想合并:
答案 0 :(得分:0)
像大多数问题一样,最终会回答一个问题:
public static int MergeColors(int backgroundColor, int foregroundColor) {
final byte ALPHA_CHANNEL = 24;
final byte RED_CHANNEL = 16;
final byte GREEN_CHANNEL = 8;
final byte BLUE_CHANNEL = 0;
final double ap1 = (double)(backgroundColor >> ALPHA_CHANNEL & 0xff) / 255d;
final double ap2 = (double)(foregroundColor >> ALPHA_CHANNEL & 0xff) / 255d;
final double ap = ap2 + (ap1 * (1 - ap2));
final double amount1 = (ap1 * (1 - ap2)) / ap;
final double amount2 = amount1 / ap;
int a = ((int)(ap * 255d)) & 0xff;
int r = ((int)(((float)(backgroundColor >> RED_CHANNEL & 0xff )*amount1) +
((float)(foregroundColor >> RED_CHANNEL & 0xff )*amount2))) & 0xff;
int g = ((int)(((float)(backgroundColor >> GREEN_CHANNEL & 0xff )*amount1) +
((float)(foregroundColor >> GREEN_CHANNEL & 0xff )*amount2))) & 0xff;
int b = ((int)(((float)(backgroundColor & 0xff )*amount1) +
((float)(foregroundColor & 0xff )*amount2))) & 0xff;
return a << ALPHA_CHANNEL | r << RED_CHANNEL | g << GREEN_CHANNEL | b << BLUE_CHANNEL;
}