Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试将 UINT32 颜色格式从 AaBbGgRr 转换为 C++ 中的 AaRrGgBb。Aa = Alpha,Bb = 蓝色,Gg = 绿色 Rr = 红色。通过转换,我的意思是切换 Bb 和 Rr 的值。有人知道我怎么能做到这一点吗?
您可以使用掩码和位移来实现此目的:
uint32_t newValue = oldValue; newValue = newValue & 0xFF00FF00; // open new space to insert the bits newValue = ((oldValue & 0xFF)<< 16) | newValue; // change BB newValue = ((oldValue & 0x00FF0000) >> 16) | newValue; // Change RR