I've got a method for alpha blending:
public static int alphaBlend(int c1, int c2) {
int a1 = (c1 & 0xff000000) >>> 24;
int r1 = (c1 & 0x00ff0000) >> 16;
int r2 = (c2 & 0x00ff0000) >> 16;
int g1 = (c1 & 0x0000ff00) >> 8;
int g2 = (c2 & 0x0000ff00) >> 8;
int b1 = (c1 & 0x000000ff);
int b2 = (c2 & 0x000000ff);
float src_alpha = ((float)a1) / 255.0f;
int red = (int) ((r1 * src_alpha) + (r2 * (1.0f - src_alpha)));
int green = (int) ((g1 * src_alpha) + (g2 * (1.0f - src_alpha)));
int blue = (int) ((b1 * src_alpha) + (b2 * (1.0f - src_alpha)));
return (a1 << 24) | (red << 16) | (green << 8) | blue;
}
But sometimes this gives the wrong color (I guess because I don't use the second color's alpha). Could anyone explain how to fix this?
a1
back into the result? You don't actually do anything to that value. \$\endgroup\$