I have CMYK color values ( 0, 0.58 ,1 ,0 ) . Now I have to convert to its Integer equivalent using C# . I think it is possible using Bitwise operator but not sure .
Kindly assist me how can achieve same .
Thanks, Pawan
I have CMYK color values ( 0, 0.58 ,1 ,0 ) . Now I have to convert to its Integer equivalent using C# . I think it is possible using Bitwise operator but not sure .
Kindly assist me how can achieve same .
Thanks, Pawan
Try this:
float c = 0.0;
float y = 0.58;
float m = 1.0;
float k = 0.0;
uint intColor = (uint)(c * 255) << 24;
intColor += (uint)(y * 255) << 16;
intColor += (uint)(m * 255) << 8;
intColor += (uint)(k * 255) << 0;
Here intColor
will be a 32-bit unsigned integer, containing the byte value of the C, Y, M and K components of the color, respectively. To convert back to the components from the integer, simply invert all the operations and their order:
float c = ((intColor & 0xFF000000) >> 24) / 255.0f;
float y = ((intColor & 0x00FF0000) >> 16) / 255.0f;
float m = ((intColor & 0x0000FF00) >> 8) / 255.0f;
float k = ((intColor & 0x000000FF) >> 0) / 255.0f;