将 UINT32 颜色格式从 AaBbGgRr 转换为 AaRrGgBb

Converting UINT32 color format from AaBbGgRr to AaRrGgBb

本文关键字:转换 AaRrGgBb AaBbGgRr UINT32 颜色 格式      更新时间:2023-10-16

我正在尝试在c ++中将UINT32颜色格式从AaBbGgRr转换为AaRrGgBb。Aa = 阿尔法,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