C# 如何使颜色变亮
C# How to brighten colors
我正在做快速傅里叶变换。所以return值在0-255范围内,音量越大值越大
现在我有各种颜色的不同造型。根据声音文件中同一点的音量,FFT 可以 return 例如 1(低音量)或例如155(高音量)
我需要根据 return 值 (0-255)[=11] 将形状的 FillColor 变亮或(return 到原始颜色,如果 0 returned) =]
那么我该如何:
a)根据音量(音量0-100)缩放return值
b) 使颜色变亮(例如按比例 return 值变亮)
注意。如果值 > 0
,颜色变亮很重要
为那些认为我 DEMAND 有帮助的人编辑。
private void _t_Tick(object sender, EventArgs e)
{
int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT8192); //get ch.annel fft data
if (ret < -1) return;
int x, y;
int b0 = 0;
//computes the spectrum data, the code is taken from a bass_wasapi sample.
for (x = 0; x < _lines; x++)
{
float peak = 0;
int b1 = (int)Math.Pow(2, x * 10.0 / (_lines - 1));
if (b1 > 1023) b1 = 1023;
if (b1 <= b0) b1 = b0 + 1;
for (; b0 < b1; b0++)
{
if (peak < _fft[1 + b0]) peak = _fft[1 + b0];
}
y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
if (y > 255) y = 255;
if (y < 0) y = 0;
_spectrumdata.Add((byte)y);
//Console.Write("{0, 3} ", y);
}
if (DisplayEnable) _spectrum.Set(_spectrumdata);
for (int i = 0; i < _spectrumdata.ToArray().Length; i++)
{
try
{
//if (_spectrumdata[i] > mth)
//{
// _shapes.ToArray()[i].FillColor = _colors.ToArray()[i];// Class1.Increase(_colors.ToArray()[i], _spectrumdata[i]);
//}
//else
//{
// _shapes.ToArray()[i].FillColor = Color.Black; //Class1.Increase(Color.Black, _spectrumdata[i]);
//}
//double d = Math.Round(((float)_spectrumdata[i]) / 255 , 2);
double[] d = GetScaling(_spectrumdata.ToArray(), 0,1);
if (_spectrumdata[i] > mth)
{
_shapes.ToArray()[i].FillColor = ControlPaint.Light(_colors.ToArray()[i], Convert.ToSingle(d[i]));
}
else
{
_shapes.ToArray()[i].FillColor = _colors.ToArray()[i]; ;// Color.Black; //Class1.Increase(Color.Black, _spectrumdata[i]);
}
}
catch (Exception)
{
}
try
{
_chart.Series["wave"].Points.RemoveAt(0);
}
catch (Exception)
{
}
}
_spectrumdata.Clear();
int level = BassWasapi.BASS_WASAPI_GetLevel();
_l.Value = (Utils.LowWord32(level));
_r.Value = (Utils.HighWord32(level));
if (level == _lastlevel && level != 0) _hanctr++;
_lastlevel = level;
//Required, because some programs hang the output. If the output hangs for a 75ms
//this piece of code re initializes the output so it doesn't make a gliched sound for long.
if (_hanctr > 3)
{
_hanctr = 0;
_l.Value = (0);
_r.Value = (0);
Free();
Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
_initialized = false;
Enable = true;
}
}
我完全不知道你在说什么,但如果你只是想把一个数字 1-155 放大到 1-255,试试乘法。
一些简单的数学运算 (155x = 255) 表明您要乘以的数字 x 等于 51/31 或 ~1.64516129。
因此,您要做的是将原始亮度(假设为 35)乘以 1.64516129。
35 * 1.64516129 = 57.58064.
您可以使用 Math class 将数字四舍五入为最接近的整数,然后您可以将其用作新的亮度值。
我正在做快速傅里叶变换。所以return值在0-255范围内,音量越大值越大
现在我有各种颜色的不同造型。根据声音文件中同一点的音量,FFT 可以 return 例如 1(低音量)或例如155(高音量)
我需要根据 return 值 (0-255)[=11] 将形状的 FillColor 变亮或(return 到原始颜色,如果 0 returned) =]
那么我该如何: a)根据音量(音量0-100)缩放return值 b) 使颜色变亮(例如按比例 return 值变亮)
注意。如果值 > 0
,颜色变亮很重要为那些认为我 DEMAND 有帮助的人编辑。
private void _t_Tick(object sender, EventArgs e)
{
int ret = BassWasapi.BASS_WASAPI_GetData(_fft, (int)BASSData.BASS_DATA_FFT8192); //get ch.annel fft data
if (ret < -1) return;
int x, y;
int b0 = 0;
//computes the spectrum data, the code is taken from a bass_wasapi sample.
for (x = 0; x < _lines; x++)
{
float peak = 0;
int b1 = (int)Math.Pow(2, x * 10.0 / (_lines - 1));
if (b1 > 1023) b1 = 1023;
if (b1 <= b0) b1 = b0 + 1;
for (; b0 < b1; b0++)
{
if (peak < _fft[1 + b0]) peak = _fft[1 + b0];
}
y = (int)(Math.Sqrt(peak) * 3 * 255 - 4);
if (y > 255) y = 255;
if (y < 0) y = 0;
_spectrumdata.Add((byte)y);
//Console.Write("{0, 3} ", y);
}
if (DisplayEnable) _spectrum.Set(_spectrumdata);
for (int i = 0; i < _spectrumdata.ToArray().Length; i++)
{
try
{
//if (_spectrumdata[i] > mth)
//{
// _shapes.ToArray()[i].FillColor = _colors.ToArray()[i];// Class1.Increase(_colors.ToArray()[i], _spectrumdata[i]);
//}
//else
//{
// _shapes.ToArray()[i].FillColor = Color.Black; //Class1.Increase(Color.Black, _spectrumdata[i]);
//}
//double d = Math.Round(((float)_spectrumdata[i]) / 255 , 2);
double[] d = GetScaling(_spectrumdata.ToArray(), 0,1);
if (_spectrumdata[i] > mth)
{
_shapes.ToArray()[i].FillColor = ControlPaint.Light(_colors.ToArray()[i], Convert.ToSingle(d[i]));
}
else
{
_shapes.ToArray()[i].FillColor = _colors.ToArray()[i]; ;// Color.Black; //Class1.Increase(Color.Black, _spectrumdata[i]);
}
}
catch (Exception)
{
}
try
{
_chart.Series["wave"].Points.RemoveAt(0);
}
catch (Exception)
{
}
}
_spectrumdata.Clear();
int level = BassWasapi.BASS_WASAPI_GetLevel();
_l.Value = (Utils.LowWord32(level));
_r.Value = (Utils.HighWord32(level));
if (level == _lastlevel && level != 0) _hanctr++;
_lastlevel = level;
//Required, because some programs hang the output. If the output hangs for a 75ms
//this piece of code re initializes the output so it doesn't make a gliched sound for long.
if (_hanctr > 3)
{
_hanctr = 0;
_l.Value = (0);
_r.Value = (0);
Free();
Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
_initialized = false;
Enable = true;
}
}
我完全不知道你在说什么,但如果你只是想把一个数字 1-155 放大到 1-255,试试乘法。
一些简单的数学运算 (155x = 255) 表明您要乘以的数字 x 等于 51/31 或 ~1.64516129。
因此,您要做的是将原始亮度(假设为 35)乘以 1.64516129。
35 * 1.64516129 = 57.58064.
您可以使用 Math class 将数字四舍五入为最接近的整数,然后您可以将其用作新的亮度值。