objective c - NSColor | Creating Color from RGB Values -
in application, rgb values unsigned character not more 255, using nscolor api create color , make use of draw font , background color,
this function have written
+(nscolor *)getcolorfromrgb:(unsigned char)r blue:(unsigned char)b green:(unsigned char)g { cgfloat rfloat = r/255.0; cgfloat gfloat = g/255.0; cgfloat bfloat = b/255.0; // return [nscolor colorwithcalibratedred:((float)r/255.0) green:((float)g/255.0) blue:((float)b/255.0) alpha:1.0]; return [nscolor colorwithcalibratedred:rfloat green:gfloat blue:bfloat alpha:1.0]; }
in case, when compare color using rgb value in rgb palate, color not matching, example, when pass ,
r = 187, g = 170, b = 170,
it should draw light gray, getting complete whilte color, in case,
anyone has idea, doing wrong,
kind regards
rohan
if passing input components out of 255 , want restrict within 255 safety purpose, can try this:
cgfloat rfloat = r % 255.0; cgfloat gfloat = g % 255.0; cgfloat bfloat = b % 255.0;
instead of divide use % value.
Comments
Post a Comment