且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java Applet,获取paint()中使用的颜色名称

更新时间:2023-01-27 14:39:39

如果您真的愿意,应该可以这样做.我会先将颜色从 RGB 转换为 HSV.然后将色调划分为区域.通常红色是 0 度,然后是 60 度的黄色,120 度的绿色,180 度的青色,240 度的蓝色,到 300 度的洋红色或紫色,然后变回红色.您可以使用饱和度来判断该值是否为灰度.该值可以告诉您亮"、常规"或暗".您可能希望对某些值进行特殊处理,例如橙色/棕色范围内的值.还有一些有特殊的名字,比如浅不饱和红"就是粉红色.

It should be possible to do something like this if you really want to. I would start by converting the color from RGB to HSV. Then partition the hues into regions. Usually red is at 0 degrees, followed by yellow at 60, green at 120, cyan at 180, blue at 240, to magenta or purple at 300 degrees, then back to red. You can use the saturation to tell if the value is grayscale or not. The value can tell you "bright", "regular" or "dark". You might want to special-case some values, such as those in the orange/brown range. And some have special names, like "light unsaturated red" is pink.

对于它的价值,我发布了一个 此处为 Objective-C 版本.可能使用上面链接的***文章将其转换为 Java 应该相当容易.

For what it's worth, I've posted an Objective-C version here. It should be fairly easy to convert to Java possibly using the wikipedia article linked above.