【问题标题】:C# How to brighten colorsC#如何使颜色变亮
【发布时间】:2018-03-26 18:23:53
【问题描述】:

我正在做快速傅里叶变换。所以返回值在 0-255 范围内,音量越大,值越大

现在我有各种颜色的不同形状。根据声音文件中同一点的音量,FFT 可以返回例如 1(低音量)或例如155(高音量)

我需要根据返回值(0-255)对形状的FillColor进行调亮或(返回0则返回原色)

那么我该怎么做: a) 根据音量(音量0-100)缩放返回值 b) 使颜色变亮(例如按比例返回值变红)

注意。如果值> 0,颜色变亮很重要

为那些认为我需要提供帮助的人编辑。

 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;
            }
        }

【问题讨论】:

  • 总是一个跛脚的反对者。你能回答这个问题吗?
  • 总是一个跛脚的人,试图让别人完成所有事情。你至少能说明你试图做什么以及为什么没有成功吗?阅读How to Ask 并发布minimal reproducible example
  • 我第一次看到你的问题时,我只是因为我不太了解你正在处理的主题而忽略了它。我再次检查并看到了您的评论,这引发了我的大脑响应,点击了否决票按钮。需要帮助的态度令人讨厌。
  • 是的..我用所有的比特广告字节和夜间爬行的一切力量要求你真棒的downvoter帮助我,因为我很无助等等等等..无聊
  • @Camilio。 “试图让别人完成所有事情”?那么这个论坛的目的是什么?

标签: c# colors fft


【解决方案1】:

我完全不知道你在说什么,但如果你只是想把一个数字 1-155 放大到 1-255,试试乘法。

一些简单的数学运算 (155x = 255) 表明 x,您必须乘以的数字,等于 51/31 或 ~1.64516129。

因此,您要做的是将原始亮度(假设为 35)乘以 1.64516129。

35 * 1.64516129 = 57.58064。

您可以使用Math 类将数字四舍五入为最接近的整数,然后您可以将其用作新的亮度值。

【讨论】:

  • 老兄.. 你是唯一一个忽略所有废话并专注于问题的人。
猜你喜欢
  • 2020-06-09
  • 1970-01-01
  • 2013-01-09
  • 2015-07-21
  • 2010-09-13
  • 1970-01-01
  • 2013-08-18
  • 1970-01-01
  • 2011-07-25
相关资源
最近更新 更多