tags:

views:

16

answers:

2

I need to convert Value of NSColor object into 8 bit integer value

code :

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;

value that I received is 0.

i am not getting where I am wrong. So anyone help me out plz.

A: 

is readable now??

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;

Greshi Gupta
You should edit your question to clarify instead of posting answers.
zneak
ok sorry, actually I am new to stack overflow so don't know when to use and what to use.next time I will.
Greshi Gupta
A: 

I come to know the problem,actually I need to write

int value = (a << 24) | (r<< 16) | (g << 8) | b; in place of uint8_t value = (a << 24) | (r<< 16) | (g << 8) | b;

Greshi Gupta