2017-10-14 136 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