c# - get single color values from argb number -


im learning c# , following problem im trying solve taking number stored string , getting a, r, g, b values.

so want go

string s = "4280427042"; 

to

int = 255; int r = 22; int g = 22; int b = 22; 

what best approach?

you can convert string unsigned 32-bit integer, , use bitconverter individual bytes this:

string s = "4280427042";  uint argb = convert.touint32(s);  byte[] values = bitconverter.getbytes(argb);  int = values[3]; int r = values[2]; int g = values[1]; int b = values[0]; 

quoting this msdn reference:

the order of bytes in array returned getbytes method depends on whether computer architecture little-endian or big-endian.

this means need careful order of bytes. can use bitconverter.islittleendian that.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -