i have an argb value in the parameter of a function and the function needs to get rid of the agb values and only keep the r. How would you do that? thank-you
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That is done with bitwise shifting and bitwise AND.
The uint in a 32 bit integer. Each of the A,R,G,B takes up 8 of its bits(one byte).
And they appear I the same order as the name implies A,R,G,B
To get out b you just need to mask out all the other bits with a bitwise AND statement.
a=argb&255
because 255 in binary is 11111111, it only keeps the needed bits.
for g you first need to shift the bits then do the above.
g=argb>>8&255
r is same but shift 16 bits
r=argb>>16&255
and a
a=argb>>24&255
Hope that helps