objective c - Can't convert hex color to rgb because of int representation -


i'm downloading hex color web , when try convert rgb it's not working.

i'm using function:

#define uicolorfromrgb(rgbvalue) [uicolor colorwithred:((float)((rgbvalue & 0xff0000) >> 16))/255.0 green:((float)((rgbvalue & 0xff00) >> 8))/255.0 blue:((float)(rgbvalue & 0xff))/255.0 alpha:1.0] 

i think problem when value internet (for example 000) when convert int can pass argument function above, int represented 0 function doesn't recognize color. same thing example 090 when in int 90.

you need think of hex colour string , process each component separately.

the colour #3b9 has digits "3" "b" , "9"

however, looking here see 3 digit representation, characters doubled.

so in case colour #33bb99: red = 3*16+3 = 51 green = 11*16+11 = 187 blue = 8*16+8 = 136 alpha = 255

so colour '#3b9' become: [51/255.0, 187/255.0, 136/255.0, 1.0]

so should first determine if string representing colours in compressed way , duplicate digits if necessary. convert pairs of digits decimal value , convert uicolor.

hope helps, , hope calculations correct. not objective-c wont provide code, should easy enough write own function, although bet function exists somewhere.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -