我正在使用IntBuffer来操作Bitmap的像素,但缓冲区中的值应该是AABBGGRR,而颜色常量是AARRGGBB.我知道我可以使用Color.argb,Color.a,…来反转,但我认为它并不完美.
我需要操作非常多的像素,所以我需要一种能够在短时间内执行此运算符的算法.我想到了这个Bit Expression,但它不正确:
0xFFFFFFFF ^ pSourceColor
如果没有更好的,也许我将使用位移操作符(执行Color.a,…)而不是调用函数来减少时间.
编辑:
这是我目前转换的函数,虽然我认为应该有更好的算法(更少的运算符)来执行它:
private int getBufferedColor(final int pSourceColor) {
return
((pSourceColor >> 24) << 24) | // Alpha
((pSourceColor >> 16) & 0xFF) | // Red -> Blue
((pSourceColor >> 8) & 0xFF) << 8 | // Green
((pSourceColor) & 0xFF) << 16; // Blue -> Red
}