3

WritableBitmap を使用して「滑らかな」線をレンダリングする必要があります。私は WritableBitmapExtenstions を使用しています

12 ミリ秒ごとに (X,Y) で構成される 12 のポイントを取得します。ここで、Y は画面の中心に正規化され、X はイメージ サーフェス (ビットマップ) 上のピクセルを表します。

初期化 :

 _wb =  new WriteableBitmap((int)mainGrid.ActualWidth, (int)mainGrid.ActualHeight, 96.0, 96.0, PixelFormats.Pbgra32, null);
 image.Source = _wb;

 CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);

CompositionTarget_Rendering :

   Point [] points = null;
   if (blocks.TryDequeue(out points)) // blocks is a ConcurrentQueue which gets enqueued on a timer interval on another thread.
   {
       using (_wb.GetBitmapContext())
       {                    
           Draw(points);
       }
   }

描く :

   private void Draw(Point[] points)
   {
        int x1, y1, x2, y2;

        if (lastX != 0 && lastY != 0)
        { // Draw connection to last line segment.
            x1 = lastX;
            y1 = lastY;
            x2 = (int)points[0].X;
            y2 = (int)points[0].Y;

            _wb.DrawLine(x1, y1, x2, y2, Colors.Red);
        }

        for (int i = 0; i < points.Count() - 1; i++)
        {// draw lines. [0],[0] - [1],[1]  ; [1],[1] - [2],[2]   .....and so on.
            x1 = (int)points[i].X;
            y1 = (int)points[i].Y;
            x2 = (int)points[i + 1].X;
            y2 = (int)points[i + 1].Y;

            _wb.DrawLine(x1, y1, x2, y2, Colors.Red);
        }

        lastX = (int)points[points.Count() - 1].X;
        lastY = (int)points[points.Count() - 1].Y;      
   }  

結果 :

ここに画像の説明を入力

線は正確に配置されていますが、描画方法はスムーズではなく、Writablebitmap を使用して Rendering イベントですべての線を描画しましたが、各セグメントはまだバッチとしてレンダリングされていました。

結論として、これを滑らかにするために一度に1ピクセルずつ描画する必要がありますか? WritablebitmapEx 曲線サンプルのように見える場合は、"WriteableBitmapExCurveSample.Wpf" という名前のプロジェクト (上記のリンクからサンプルをダウンロードする必要があります)

私が達成したくないような滑らかさを見ることができます。

4

2 に答える 2