Java小程序,得到在涂料中使用的颜色的名称() [英] Java Applet, get the name of the colour being used in paint()

查看:173
本文介绍了Java小程序,得到在涂料中使用的颜色的名称()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Java小程序的paint()方法的图形对象,

When using the graphics object in the paint() method of a Java Applet,

有谁知道如何使用方法上的图形对象,由此将返回所使用的颜色的名称?

Does anyone know how to use a method on the graphics object whereby it will return the name of the color being used?

使用g.setColor(Color.red)后;

After using g.setColor(Color.red);

然后绘制矩形

香港专业教育学院尝试使用g.getColor()的toString();

Ive tried using g.getColor().toString();

但是,这仅返回一个像这样的字符串:java.awt.Applet [R:255 G:0 B:0]

But this only returns a string like this: "java.awt.Applet[r:255 g:0 b:0]"

即时通讯寻求找回红色如果可能的

Im looking to get back "Red" if its possible

推荐答案

这应该可以做这样的事情,如果你真的想。我会通过颜色从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.

有关它的价值,我已经发布了<一个href=\"http://stackoverflow.com/questions/19526374/how-to-print-rgb-colors-name-in-objective-c/19620429#19620429\">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.

这篇关于Java小程序,得到在涂料中使用的颜色的名称()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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