Programming Tutorials

Convert Image to Base64 String in C#

By: Syed in Csharp Tutorials on 2011-01-10  

This article will help you to learn how we can convert an image into a base64 string and base64 string back to image.
public string ImageToBase64(Image image, 
  System.Drawing.Imaging.ImageFormat format)
{
  using (MemoryStream ms = new MemoryStream())
  {
    // Convert Image to byte[]
    image.Save(ms, format);
    byte[] imageBytes = ms.ToArray();

    // Convert byte[] to Base64 String
    string base64String = Convert.ToBase64String(imageBytes);
    return base64String;
  }
}





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Csharp )

Latest Articles (in Csharp)