简体   繁体   中英

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).

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

Which is great, however, I absolutely require to have black/white as selectable colors too , but this RGB map doesn't have it.

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. You are mapping two of them right now (hue and saturation), while keeping lightness at a constant value 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.

You could use the JColorChooser . This tutorial shows you how.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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