2010-08-27 26 views
1

我需要值轉換NSColor對象轉換到8位的整數值如何改變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

請格式化您的代碼,它的可讀性 – 2010-08-27 11:10:36

+0

現在可讀? – 2010-08-27 11:15:37

回答

1

我來認識這個問題,其實我需要寫

int值=(A < < 24)| (r < < 16)| (g < < 8)| b; 代替 uint8_t value =(a < < 24)| (r < < 16)| (g < < 8)| b;