Converting any Image to Base64 String using C#.

Posted by vishalneeraj-24503 under ASP.NET category on | Points: 40 | Views : 5982
Write below C# Code and pass Image and also pass file format of the image,it may be any format like Jpeg,Gif or anything.
public string Convert_ImageTo_Base64(Image image,System.Drawing.Imaging.ImageFormat format)
using (MemoryStream ms = new MemoryStream())
//First Convert Image to byte[]
image.Save(ms, format);
byte[] imageBytes = ms.ToArray();

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

Comments or Responses

Posted by: Jonygreen on: 9/24/2015 Level:Starter | Status: [Member] | Points: 10
I'm not a developer, i always use the free online base64 string converter( ) to encode and decode base64.

Login to post response