Windows 10 Home 64bit、
Visual Studio 2017 Community Edition、
.NET Framework 4.6、WPF + C# で開発しています。
WPF でグラフコントロールを作成してみようと思い、
テスト的に下記のような 3,000 個の点を描画するコントロールを作成しました。
C#
1namespace GraphTest 2{ 3 using System; 4 using System.Threading.Tasks; 5 using System.Windows; 6 using System.Windows.Media; 7 8 public class GraphControl : FrameworkElement 9 { 10 private SolidColorBrush _brush; 11 private Pen _pen; 12 private Random _rand; 13 14 public GraphControl() 15 { 16 this._brush = new SolidColorBrush(Colors.Orange); 17 this._brush.Freeze(); 18 19 this._pen = new Pen(this._brush, 1.0); 20 this._pen.Freeze(); 21 22 this._rand = new Random(); 23 } 24 25 protected override void OnRender(DrawingContext drawingContext) 26 { 27 for (var i = 0; i < 3000; i++) 28 { 29 drawingContext.DrawEllipse(this._brush, this._pen, new Point((double)this._rand.Next(0, (int)this.RenderSize.Width), (double)this._rand.Next(0, (int)this.RenderSize.Height)), 3.0, 3.0); 30 } 31 32 Task.Run(async () => 33 { 34 await Task.Delay(1); 35 await Dispatcher.BeginInvoke((Action)this.InvalidateVisual); 36 }); 37 } 38 } 39}
OnRender() の最後に InvalidateVisual() を非同期的に呼び出しているため、
ずっと描画し続けるようになっています。
このとき、
Visual Studio の診断ツールでプロセスメモリを確認すると、
非常に高い頻度で GC がおこなわれていることがわかりました。
そして、おそらくこれが原因で描画速度がかなり遅くなっていました。
OnRender() の中では変なことはしていないつもりなので、
GC が発生する原因は DrawingContext.DrawEllipse() の中にあると思っています。
つまりこの描画方法ではそもそも限界があると認識しています。
しかし、世の中には SciChart など、
非常に高速な描画を実現しているものがあります。
こういったものは一体どのようにして実装しているのでしょうか。
回答1件
あなたの回答
tips
プレビュー
2018/08/27 12:37
2018/08/27 16:32
2018/08/27 23:00