我需要将NSColor对象的值转换为8位整数值
代码:
uint8_t r = (uint32_t)(MIN(1.0f, MAX(0.0f, [[CWhiteBoardController ReturnFillColor] redComponent])) * 0xff);
uint8_t g = (uint32_t)(MIN(1.0f, MAX(0.0f, [[CWhiteBoardController ReturnFillColor] greenComponent])) * 0xff);
uint8_t b = (uint32_t)(MIN(1.0f, MAX(0.0f, [[CWhiteBoardController ReturnFillColor] blueComponent])) * 0xff);
uint8_t a = (uint32_t)(MIN(1.0f, MAX(0.0f, [[CWhiteBoardController ReturnFillColor] alphaComponent])) * 0xff);
uint8_t value = (a << 24) | (r<< 16) | (g << 8) | b;
我收到的值是0。
我没有得到我错的地方。 所以任何人都可以帮我解决问题。
答案 0 :(得分:1)
我开始知道这个问题,实际上我需要写
int value =(a <&lt; 24)| (r <&lt; 16)| (g <&lt; 8)| b; 代替 uint8_t value =(a&lt;&lt;&lt; 24)| (r <&lt; 16)| (g <&lt; 8)| B;