[英]how to convert rgb color to hex color - kotlin
This is what I do这就是我所做的
val color = String.format("0XFF%02x%02x%02x", r, g, b)
this returns me a string "0XFFhexcode" I want to convert it to long, to store it and then use it as a color这将返回一个字符串“0XFFhexcode”我想将其转换为长,以存储它然后将其用作颜色
color.toLong()
I have the following error我有以下错误
java.lang.NumberFormatException: For input string: 0XFFhexcode
This code might help you:此代码可能会帮助您:
Integer.toHexString(Color.rgb(r, g, b))
You can do it simply like the following:你可以像下面这样简单地做到这一点:
val rgb = Color.rgb(red, green, blue)
val hex = String.format("#%06X", 0xFFFFFF and rgb)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.