WPF - WritablebitmapEx provides a smooth line

I need to display a "smooth" string using WritableBitmap "I am using WritableBitmapExtenstions .

Every 12 ms I get 12 points consisting of (X, Y), where Y is normalized to the center of the screen, and X is a pixel on the image surface (bitmap).

Init:

 _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);
       }
   }

Painting:

   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;      
   }  

Result:

enter image description here

Well, the lines were exactly in place, but the way it was drawn was not even even rigid, I used Writablebitmap and painted all the lines in the Rendering event, each segment still displayed as a package.

, , , ? WritablebitmapEx, "WriteableBitmapExCurveSample.Wpf" ( , )

, .

+3
2

DrawLineAa (Aa == Antialiased) DrawLine.

+2

post-fx. http://lodev.org/cgtutor/filtering.html

, asp.net, , CompositionTarget - .

+2
source

All Articles