用颜色获得R,G,B的值 [英] Get value of R, G, B by color

查看:489
本文介绍了用颜色获得R,G,B的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用户键入颜色(例如白色,红色,...),那么如何获得R,G,B的颜色与用户的颜色值?

I have user type the color (e.g. White, Red,...) so how can I get value of R, G, B with the color of user gave?

我有一个函数(float r,float g,float b)来设置一个节点的颜色。所以我让用户输入他们想要的颜色名称,然后我想转换该颜色名称为我的函数获取r,g,b值。

I have a function (float r, float g, float b) to set color a node. So i let the user type the color name they want, then i want to convert that color name to get r, g, b value for my function.

推荐答案

颜色定义了表示基本颜色的枚举数有限此代码摘录使用反射从其名称映射到RGB表示形式。

Color defines a limited number of enums representing basic colours. This code excerpt uses reflection to map from their names to the RGB representations.

除此之外,您还需要维护一个颜色/ RGB值的地图,或者一组系统属性,并使用 Color.getColor(String name)

Other than that you'll have to maintain a map of colors/RGB values, or possibly a set of system properties, and use Color.getColor(String name).

这篇关于用颜色获得R,G,B的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆