Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以增量方式绘制多段线线段会创建视觉瑕疵_C#_Wpf_System.reactive - Fatal编程技术网

C# 以增量方式绘制多段线线段会创建视觉瑕疵

C# 以增量方式绘制多段线线段会创建视觉瑕疵,c#,wpf,system.reactive,C#,Wpf,System.reactive,我有一个示例应用程序,可以从文件中读取音频数据并渲染立体声波形 由于读取音频数据需要一些时间,我决定以增量方式进行渲染。当数据可用时,会向波形中添加额外的点 然而,这样的渲染创建了一个令人讨厌的“喇叭”工件,如屏幕截图所示 此代码段说明了如何设置PolylineSegment实例: <!-- language: c# --> var leftWaveformPolyLine = new PolyLineSegment(); var rightWaveformPolyLine = n

我有一个示例应用程序,可以从文件中读取音频数据并渲染立体声波形

由于读取音频数据需要一些时间,我决定以增量方式进行渲染。当数据可用时,会向波形中添加额外的点

然而,这样的渲染创建了一个令人讨厌的“喇叭”工件,如屏幕截图所示

此代码段说明了如何设置PolylineSegment实例:

<!-- language: c# -->
var leftWaveformPolyLine = new PolyLineSegment();
var rightWaveformPolyLine = new PolyLineSegment();
Point StartPoint() => new Point(_waveformDimensions.LeftMargin(), centerHeight);
_leftPath.Data = new PathGeometry(new[] { new PathFigure(StartPoint(), new[] { leftWaveformPolyLine }, false) });
_rightPath.Data = new PathGeometry(new[] { new PathFigure(StartPoint(), new[] { rightWaveformPolyLine }, false) });

我很想弄清楚是什么原因导致了视觉伪影,以及我可以采取什么步骤来消除它。

在读取流时,多边形线的中心看起来越来越偏离中心,但我们缺少了相当多的代码,因此目前只能推测。你确定在任何一点上,线的中心都不会因为计算中的某些错误而移动吗?我假设所有浮点数都是正值?如果是这样,为什么一些多段线呈现为负面效果?看起来不是这样,因为当数据在前面可用时,多段线会立即填充,并且不会出现任何视觉伪影。
<!-- language: c# -->
var observable = Tune.WaveformStream(); // this is an instance of IObservable<float>
_waveformBuildDisposable = observable.ObserveOn(_uiContext) // UI context since we need to draw     on the UI thread
    .Buffer(20) // take 20 floats at a time
    .Subscribe(
        renderWaveform.DrawWfPointByPoint, // this one does the drawing
        renderWaveform.CompleteWaveform); // this is called when we're done
Task.Run(() => observable.Waveform(8000)); // the method "Waveform" does the actual analysis of the audio data and provides the stream of floats consumed above, the parameter "8000" is a "resolution" and is not important here.
<!-- language: c# -->
var height = _mainCanvas.RenderSize.Height / 2.0d;
var location = ((_pointsDrawn / 2) * _pointThickness) + _waveformDimensions.LeftMargin(); // where to draw - increasing by the point thickness
_leftWaveformPolyLine.Points.Add(new Point(_xLocation, _centerHeight - left * height)); // this adds a point to the left channel
_rightWaveformPolyLine.Points.Add(new Point(_xLocation, _centerHeight + right * height)); // this adds a point to the right channel