[英]how to convert rgb color to hex color - kotlin
這就是我所做的
val color = String.format("0XFF%02x%02x%02x", r, g, b)
這將返回一個字符串“0XFFhexcode”我想將其轉換為長,以存儲它然后將其用作顏色
color.toLong()
我有以下錯誤
java.lang.NumberFormatException: For input string: 0XFFhexcode
此代碼可能會幫助您:
Integer.toHexString(Color.rgb(r, g, b))
你可以像下面這樣簡單地做到這一點:
val rgb = Color.rgb(red, green, blue)
val hex = String.format("#%06X", 0xFFFFFF and rgb)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.