aishen944-163.com
转贴请注明出处,谢谢!!
其实透明贴图的原理就是进行xor运算,
基本公式:A xor A = 0 A xor 0 = A A xor A xor B = B
假如现在有两张图片,一张是我们要对其进行贴图的图片A, 另外一张是要被贴图的图片B
1, 复制图片B的一份拷贝为C
2, 将C中指定的背景色变为全白(0xffffff),其他颜色变为全黑(0x00)
3, 依次执行如下运算:
A xor B
A and C
A xor B
对于C中的白色执行运算后的结果如下:
((A xor B) and 0xfffffff) xor B = A xor B xor B = A
对于C中的黑色执行运算后的结果如下:
((A xor B) and 0x0000) xor B = 0 xor B = B
以下是代码实例,例子中用到的两张图片在这里: