Convert a RGB colour value to Decimal

前端 未结 6 1395
梦谈多话
梦谈多话 2021-02-04 13:09

How do I convert a RGB colour value to just plain decimal?

So I have: RGB(255,255,255) is white
Its decimal equivalent is: 16777215

I have tried thinking it

6条回答
  •  天涯浪人
    2021-02-04 13:19

    A much better answer (in terms of clarity) is this:

    'Convert RGB to LONG:
     LONG = B * 65536 + G * 256 + R
    
    'Convert LONG to RGB:
     B = LONG \ 65536
     G = (LONG - B * 65536) \ 256
     R = LONG - B * 65536 - G * 256
    

    LONG is your long integer (decimal) that you want to make. Easy huh? Sure, bitshift

提交回复
热议问题