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))
{
using (_wb.GetBitmapContext())
{
Draw(points);
}
}
Painting:
private void Draw(Point[] points)
{
int x1, y1, x2, y2;
if (lastX != 0 && lastY != 0)
{
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++)
{
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:

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"
( , )
, .