How to convert hex to rgb using Java?

后端 未结 19 2034
-上瘾入骨i
-上瘾入骨i 2020-11-27 13:46

How can I convert hex color to RGB code in Java? Mostly in Google, samples are on how to convert from RGB to hex.

19条回答
  •  时光取名叫无心
    2020-11-27 13:55

    Lots of these solutions work, but this is an alternative.

    String hex="#00FF00"; // green
    long thisCol=Long.decode(hex)+4278190080L;
    int useColour=(int)thisCol;
    

    If you don't add 4278190080 (#FF000000) the colour has an Alpha of 0 and won't show.

提交回复
热议问题