2017-10-14 121 views
-4

我正在做FastFourier变换。所以返回值在0-255范围内,体积越大,数值越大C#如何增亮颜色

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

我需要亮或(返回到原来的颜色,如果返回0),根据返回值(0-255)

所以形状的填充颜色怎么办我: 一)按照音量缩放返回值(音量0-100) b)增亮颜色(例如,红色按缩放的返回值)

注意。其重要的是,如果价值> 0,颜色变亮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; 
      } 
     } 
+0

总是一个跛脚downvoter。你能回答这个问题吗? – Eminem

+0

总是一个跛脚的人试图让别人完成一切。你至少能证明你试图做什么,为什么它没有工作?阅读[问]并发布[mcve] –

+1

第一次看到你的问题时,我通过了它,仅仅是因为我不知道你正在使用的主题。我再次检查并看到您的评论,这引发了我的大脑中的反应,单击向下投票按钮。需要帮助的态度是光明的。 – jdphenix

回答

0

我绝对不知道什么是地狱,你是在谈论,但如果你只是想取号1-155和放大它1-255,尝试繁殖。

一些简单的数学(155x = 255)显示x必须乘以的数等于51/31或〜1.64516129。

所以,你会做的是乘以你原来的亮度,让说35,乘1.64516129。

35 * 1.64516129 = 57.58064。

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

+0

Dude ..你是唯一一个忽视所有公牛谈话并专注于问题的人。 – Eminem