Programmatically generate a color chart?

In C #, how could I generate the following image programmatically?

http://deathmatchgame.files.wordpress.com/2010/07/color_picker.png

I know well how long it will take to process. It's great. At the moment, performance is not a top priority.

Change Note that I am not interested in the correct area of ​​the image in which only the gray gradient is displayed.

+6
source share
3 answers

In appearance, this is the HSL color chart. In the code below, a 2d array of colors will be created that should match what is shown in the image. I left the FromHSL implementation to you, as well as how to get from this array to the actual image:

 const int size = 1000; const double ratio = 1.0 / size; const double saturation = 1.0; Color[,] colors = new Color[size,size]; for (int i = 0; i < size; i++) { double lightness = 1.0 - i*ratio; for (int j = 0; j < size; j++) { double hue = j*ratio; colors[i, j] = FromHSL(hue, saturation, lightness); } } 
+3
source

This image represents HSL (not HSV, white - S = 0 in HSV), with S at 100%, H on the horizontal axis and L on the vertical axis. (The grayscale gradient is S = 0) You can use the transformations http://www.bobpowell.net/RGBHSB.htm and just iterate over all the pixels in your rectangle.

Like a simple eyedropper palette, it gives you fully saturated colors (and gray, with a bit to the right).

The Windows color picker allows you to map S along the vertical axis (with L = 50%) in a large square, resulting in a gray bottom having a separate slider for L. This is less useful as a color picker palette. Another widely known color picker is the circle with a hue around the circle and saturation as a radius (usually this puts white in the center, using HSV with V = 100 and a separate slider for the value)

+4
source

Source: https://habr.com/ru/post/900798/


All Articles