문제

I am trying to convert an UINT32 color format from AaBbGgRr to AaRrGgBb in c++. Aa = Alpha, Bb = Blue, Gg = Green Rr = Red. By converting I mean switching the values of Bb and Rr. Does somebody know how I can achieve that ?

도움이 되었습니까?

해결책

You can use mask and bit shifting to achieve this:

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top