简体   繁体   English

生成RGB颜色图

[英]Generating RGB Color Map

I'm not sure exactly what it's called, but I'm trying to generate an RGB color map like what you see when creating a custom color in MS Paint (or Photoshop or any other countless applications). 我不确定它到底叫什么,但我正在尝试生成RGB颜色图,就像在MS Paint(或Photoshop或任何其他无数个应用程序)中创建自定义颜色时看到的那样。

The code I currently found and am using: 我当前找到并正在使用的代码:

private final static int COLORS_WIDTH = 256;
private final static int COLORS_HEIGHT = 256;

_colorPixmap = new Pixmap(256, 256, Format.RGB888);

for (int x = 0; x < COLORS_WIDTH; ++x)
{
    for (int y = 0; y < COLORS_HEIGHT; ++y)
    {
        float h = x / (float) COLORS_WIDTH;
        float s = (COLORS_HEIGHT - y) / (float) COLORS_HEIGHT;
        float l = 0.5f;
        Color color = HSLtoRGB(h, s, l);

        _colorPixmap.setColor(color);
        _colorPixmap.drawPixel(x, y);
    }
}

Generates this: 生成此:

http://i.imgur.com/9sHrfJR.png http://i.imgur.com/9sHrfJR.png

Which is great, however, I absolutely require to have black/white as selectable colors too , but this RGB map doesn't have it. 很棒,但是, 我也绝对需要将黑色/白色作为可选颜色 ,但是此RGB贴图没有。

I'm not good with color stuff (hue, saturation, brightness) and can't seem to tweak the code to get what I'm looking for. 我对颜色方面(色相,饱和度,亮度)不满意,并且似乎无法调整代码以获取所需的内容。

Any help / suggestions or do I need a different approach? 任何帮助/建议还是我需要其他方法?

Thanks! 谢谢!

Colour in the HSL space has three dimensions. HSL空间中的颜色具有三个维度。 You are mapping two of them right now (hue and saturation), while keeping lightness at a constant value float l = 0.5f; 您现在正在映射其中两个(色相和饱和度),同时将亮度保持在恒定值float l = 0.5f; . In order to obtain all colours you need to provide a slider for the lightness in the same way that MS Paint does. 为了获得所有颜色,您需要像MS Paint一样,为亮度提供一个滑块。

You could use the JColorChooser . 您可以使用JColorChooser This tutorial shows you how. 教程向您展示如何。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM