title: Save User Drawn Bitmap Graphics in c#
body: <p>I have made a program that allows users to draw lines onto a picturebox image but now need to save these lines to be opened at a later date. This is my current code for drawing the lines:</p>
  
  <pre><code> public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
              pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
          }
          int Drawshape;
  
  
  
  
          private Point p1, p2;
          List&lt;Point&gt; p1List = new List&lt;Point&gt;();
          List&lt;Point&gt; p2List = new List&lt;Point&gt;();
  
          private void Form1_MouseDown(object sender, MouseEventArgs e)
          {
  
  
          }
  
          private void Form1_Paint(object sender, PaintEventArgs e)
          {
  
          }
  
          private void button1_Click(object sender, EventArgs e)
          {
              Drawshape = 5;
          }
  
          private void button2_Click(object sender, EventArgs e)
          {
              Drawshape = 2;
          }
  
          private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
          {
              if (Drawshape == 5)
              {
                  if (p1.X == 0)
                  {
                      p1.X = e.X;
                      p1.Y = e.Y;
                  }
                  else
                  {
                      p2.X = e.X;
                      p2.Y = e.Y;
  
                      p1List.Add(p1);
                      p2List.Add(p2);
  
                      pictureBox1.Invalidate();
                      p1.X = 0;
                  }
              }
          }
  
          private void pictureBox1_ParentChanged(object sender, EventArgs e)
          {
  
          }
  
          private void pictureBox1_Paint(object sender, PaintEventArgs e)
          {
              Graphics G = Graphics.FromImage(pictureBox1.Image);
              if (Drawshape == 5)
              {
                  using (var p = new Pen(Color.Blue, 4))
                  {
                      for (int x = 0; x &lt; p1List.Count; x++)
                      {
                          G.DrawLine(p, p1List[x], p2List[x]);
                      }
                  }
              }
  
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {
  
          }
  
          private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
          {
              pictureBox1.Invalidate();
          }
  
          private void Save_Click(object sender, EventArgs e)
          {
  
  
  
          } 
      }
  }
  </code></pre>
  
  <p>I don't know how to save these lines and also open them again at a later time when the user wants to. I have put in open and save filedialogs but not sure how to make them do the job i want them to do. Please Help.</p>
  
  <p>Thanks</p>