c# - Converting hexadecimal color to integer -
this integer color in database : "8689404".
i change color following:
color = colorhelper.fromargb(255, byte.parse(event.labelcolor.value.tostring("x8").substring(6, 2), numberstyles.hexnumber), byte.parse(event.labelcolor.value.tostring("x8").substring(4, 2), numberstyles.hexnumber), byte.parse(event.labelcolor.value.tostring("x8").substring(2, 2), numberstyles.hexnumber))
this gives me color string "#fffc9684"
now problem unable parse color string integer, can save in database. have yet is:
byte = byte.parse(labelcolor.color.trimstart('#').substring(0, 2), system.globalization.numberstyles.hexnumber); byte b = byte.parse(labelcolor.color.trimstart('#').substring(6, 2), system.globalization.numberstyles.hexnumber); byte g = byte.parse(labelcolor.color.trimstart('#').substring(4, 2), system.globalization.numberstyles.hexnumber); byte r = byte.parse(labelcolor.color.trimstart('#').substring(2, 2), system.globalization.numberstyles.hexnumber);
this gives me:
a = 255 b = 132 g = 150 r = 252
these values correct can't compare them "8689404"
as per findings:
b = 132 = 84 g = 150 = 96 r = 252 = fc = 255 = ff
this have yet, how can have integer color string. working in winrt. help!!! in advance
this produce correct decimal value want:
int decvalue = int.parse("8496fc", system.globalization.numberstyles.hexnumber);
as can see hex value used produce decimal value consists of following colour components:
b (84) g (96) r (fc)
with component dropped.
this can calculated using substring
on full hex colour so:
string colour = labelcolor.color.trimstart('#'); string r = colour.substring(2, 2); string g = colour.substring(4, 2); string b = colour.substring(6, 2);
which can use so:
int decvalue = int.parse(b + g + r, system.globalization.numberstyles.hexnumber); //decvalue = 8689404
Comments
Post a Comment