我想将现有颜色变暗以用于渐变画笔.请问有人告诉我该怎么做?
C#,.net 2.0,GDI +
Color AdjustBrightness(Color c1, float factor)
{
float r = ((c1.R * factor) > 255) ? 255 : (c1.R * factor);
float g = ((c1.G * factor) > 255) ? 255 : (c1.G * factor);
float b = ((c1.B * factor) > 255) ? 255 : (c1.B * factor);
Color c = Color.FromArgb(c1.A,(int)r, (int)g, (int)b);
return c ;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将HSB颜色转换为RGB.我这样做的方式是
System.Windows.Media.Color winColor = value;
System.Drawing.Color drawColor = System.Drawing.Color.FromArgb(winColor.R, winColor.G, winColor.B);
Hue = (byte)(drawColor.GetHue()*255);
Saturation = (byte)(drawColor.GetSaturation()*255);
Luminosity = (byte)(drawColor.GetBrightness()*255);
Run Code Online (Sandbox Code Playgroud)
我发现,当我有FF0000,它将被转换为H = 0, S = 255, L = 127转换为RGB FF0E0E.我觉得Luminosity应该是120?或者我是否让整个HSB错误?当我在Photoshop中查看颜色选择器时,Hue为0-360度,饱和度,亮度为0-100%.我的HSB值介于0到255之间,我做错了吗?
与此类似(如何增加亮度)我想改变RGB(十六进制)颜色的色调.
说changeHue("#FF0000", 40)回报"#FFAA00"
如何将这种计算方式更改为较暗而不是较亮的颜色?
function increase_brightness(hex, percent){
// strip the leading # if it's there
hex = hex.replace(/^\s*#|\s*$/g, '');
// convert 3 char codes --> 6, e.g. `E0F` --> `EE00FF`
if(hex.length == 3){
hex = hex.replace(/(.)/g, '$1$1');
}
var r = parseInt(hex.substr(0, 2), 16),
g = parseInt(hex.substr(2, 2), 16),
b = parseInt(hex.substr(4, 2), 16);
return '#' +
((0|(1<<8) + r + (256 - r) * percent / 100).toString(16)).substr(1) +
((0|(1<<8) + g + (256 - g) * percent / 100).toString(16)).substr(1) +
((0|(1<<8) + …Run Code Online (Sandbox Code Playgroud)