title: Save createGraphics in a file as image
body: <p>How can I transfer the values of my graphics to a bitmap so I can save it as jpg or bmp file.</p>
  
  <p>here's my code:</p>
  
  <pre><code>private void pictureBox1_Paint_1(object sender, PaintEventArgs e)
      {
         using(var p = new Pen(Color.Blue, 4)){
             for (int i = 0; i &lt; _listPS.Count; i++)
             {
              e.Graphics.DrawLine(_pen, _listPS[i], _listPE[i]);
             }
         }
      }
  </code></pre>
  
  <p>suppose that _listPS and _listPE have values.</p>
  
  <p>ah! Solved it LOL! :)
  Here's my solution:</p>
  
  <pre><code>private Bitmap _mybitmap;
  private void pictureBox1_Paint_1(object sender, PaintEventArgs e)
      {   
          _mybitmap = new Bitmap(pictureBox1.Width, pictureBox1.Heigth);
          Graphics _tempg = Graphics.FromImage(_mybitmap);
  
         using(var p = new Pen(Color.Blue, 4){
             for (int i = 0; i &lt; _listPS.Count; i++)
             {
                 e.Graphics.DrawLine(_pen, _listPS[i], _listPE[i]);
                 _tempg.DrawLine(_pen, _listPS[i], _listPE[i]);
             }
  
             _tempg.Dispose();
          }
      }
  </code></pre>