title: WPF, C#: Draw a line onto existing bitmap in image control
body: <p>I have a bitmap image in an image control</p>
  
  <p>
                  
              </p>
  
  <p></p>
  
  <p>I need to draw a red line on the bitmap each time I click with the mouse onto it, at the place where I clicked the mouse.</p>
  
  <p>I first thought of creating a Line object, but found out, that I cannot add the Line. I would need a canvas. But if I put my image in a canvas, my bitmap does not stretch over the whole canvas (I found out, that the coordinates of the bitmap determine the place on the canvas, so my bitmap is wrongly displayed.)</p>
  
  <p>Then I tried using graphics</p>
  
  <pre><code>Graphics graphics = Graphics.FromImage(bitmapImg);
  graphics.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Red), 0, 0,  bitmapImg.Width, bitmapImg.Height); //not the line yet, just for testing
      graphics.DrawImage(bitmapImg, 0, 0, bitmapImg.Width,bitmapImg.Height);
          graphics.Dispose();
  </code></pre>
  
  <p>However, I don`t get anything painted onto my bitmap........</p>
  
  <p>Now I think, I probably have to get the bitmap into an array and then change the pixel color to get the line in the bitmap. I believe, that this would be very slow.</p>
  
  <p>I am now trying something with visualDrawing, however, I have not got it to work yet:-(</p>
  
  <p>What is a good way to get a line onto an existing bitmap in WPF C#???? and how to remove it?</p>
  
  <p>I would be glad for any help! Thank you! I posted it already on the MS forum page, but no answer so far.</p>