If you want to draw a line, you should not just change the colors of one pixel at a time, but rather keep the mouse position in each event processing method MouseMove.
( ) a Line . . WriteableBitmap : WPF WriteableBitmap.BackBuffer.
, :).
UPDATE
.
XAML , :
<Window x:Class="SampleWPFApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="500" Width="520" Loaded="Window_Loaded" PreviewMouseDown="Window_PreviewMouseDown">
<Grid x:Name="layoutRoot" Background="Transparent">
<Image x:Name="image" />
</Grid>
:
RenderTargetBitmap bmp = null;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
bmp = new RenderTargetBitmap((int)this.ActualWidth, (int)this.ActualHeight, 90, 90, PixelFormats.Default);
image.Source = bmp;
}
private void DrawLine(Point p1, Point p2, Pen pen, double thickness)
{
DrawingVisual drawingVisual = new DrawingVisual();
using (DrawingContext drawingContext = drawingVisual.RenderOpen())
{
pen.Thickness = thickness;
pen.StartLineCap = PenLineCap.Round;
pen.EndLineCap = PenLineCap.Round;
drawingContext.DrawLine(pen, p1, p2);
}
}