title: Download image from picturebox.image in c#.net desktop application
body: <p>I am developing a desktop application in which I want to doing a particular task i.e. <strong>Save The Image In Database</strong>, <strong>Fetch The Image From Database And Show In PictureBox</strong> and <strong>Download The Image and save in folder From Picturebox Tool</strong></p>
  
  <p>Here is the task code,</p>
  
  <ol>
  <li><strong>Save The Image In Database</strong>, in that I am using <strong>ImageToBase64</strong> function to save in database in a string format. like : <code>ImageToBase64(pictureBox1.Image, System.Drawing.Imaging.ImageFormat.Jpeg)</code></li>
  </ol>
  
  <p>ImageToBase64 Function Code : </p>
  
  <pre><code>public string ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format)
  {
      using (MemoryStream ms = new MemoryStream())
      {
          if (image != null)
          {
              // Convert Image to byte[]
              image.Save(ms, format);
              byte[] imageBytes = ms.ToArray();
  
              // Convert byte[] to Base64 String
              string base64String = Convert.ToBase64String(imageBytes);
              return base64String;
          }
          else
          {
              return null;
          }
      }
  }
  </code></pre>
  
  <p>Now for fetch the image from database and show image in picturebox</p>
  
  <pre><code>picturebox1.image = Base64ToImage(dtSelStock.Rows[0]["DesignImage"].ToString())
  </code></pre>
  
  <p>Base64ToImage Function Code:</p>
  
  <pre><code>public Image Base64ToImage(string base64String)
  {
      if (base64String != "")
      {
          // Convert Base64 String to byte[]
          byte[] imageBytes = Convert.FromBase64String(base64String);
          MemoryStream ms = new MemoryStream(imageBytes, 0,
            imageBytes.Length);
  
          // Convert byte[] to Image
          ms.Write(imageBytes, 0, imageBytes.Length);
          Image image = Image.FromStream(ms, true);
          return image;
      }
      else
      {
          return null;
      }
  }
  </code></pre>
  
  <p>So, these two task working perfectly. But the thrid and last task is to save image in folder from picturebox. I tried some of code but didnt working properly, infact showing error i.e.</p>
  
  <pre><code>pictureBox1.Image.Save("D\\Image\\'" + pictureBox1.Image + "'", ImageFormat.JPEGImage);
  </code></pre>