Given an RGB value, like 168, 0, 255
, how do I create tints (make it lighter) and shades (make it darker) of the color?
相关问题
- DBGrid - How to set an individual background color
- How to display an image represented by three matri
- How to delete a certain part of an Image?
- draw polylines with different colors on v2 maps
- How do I change the color of the navigation bar ic
相关文章
- Emacs/xterm color annoyance on Linux
- matplotlib bwr-colormap, always centered on zero
- MeshLab: How to import XYZRGB file
- How to add RGB values into setColor() in Java?
- ChartJS. Change axis line color
- set foreground color in FrameLayout in android pro
- Changing background color for a text annotation to
- Keras: Visualize ImageDataGenerator Output
Among several options for shading and tinting:
For shades, multiply each component by 1/4, 1/2, 3/4, etc., of its previous value. The smaller the factor, the darker the shade.
For tints, calculate (255 - previous value), multiply that by 1/4, 1/2, 3/4, etc. (the greater the factor, the lighter the tint), and add that to the previous value (assuming each.component is a 8-bit integer).
Note that color manipulations (such as tints and other shading) should be done in linear RGB. However, RGB colors specified in documents or encoded in images and video are not likely to be in linear RGB, in which case a so-called inverse transfer function needs to be applied to each of the RGB color's components. This function varies with the RGB color space. For example, in the sRGB color space (which can be assumed if the RGB color space is unknown), this function is roughly equivalent to raising each sRGB color component (ranging from 0 through 1) to a power of 2.2. (Note that "linear RGB" is not an RGB color space.)
See also Violet Giraffe's comment about "gamma correction".
I'm currently experimenting with canvas and pixels... I'm finding this logic works out for me better.
add to offset the 'tint' value
or something like that...
Some definitions
Creating a tint or a shade
Depending on your Color Model, there are different methods to create a darker (shaded) or lighter (tinted) color:
RGB
:To shade:
To tint:
More generally, the color resulting in layering a color
RGB(currentR,currentG,currentB)
with a colorRGBA(aR,aG,aB,alpha)
is:where
(aR,aG,aB) = black = (0,0,0)
for shading, and(aR,aG,aB) = white = (255,255,255)
for tintingHSV
orHSB
:Value
/Brightness
or increase theSaturation
Saturation
or increase theValue
/Brightness
HSL
:Lightness
Lightness
There exists formulas to convert from one color model to another. As per your initial question, if you are in
RGB
and want to use theHSV
model to shade for example, you can just convert toHSV
, do the shading and convert back toRGB
. Formula to convert are not trivial but can be found on the internet. Depending on your language, it might also be available as a core function :Comparing the models
RGB
has the advantage of being really simple to implement, but:HSV
orHSB
is kind of complex because you need to play with two parameters to get what you want (Saturation
&Value
/Brightness
)HSL
is the best from my point of view:50%
means an unaltered Hue>50%
means the Hue is lighter (tint)<50%
means the Hue is darker (shade)Lightness
part)