Convert Image to Base64


private string ImageToBase64String(string path)
{
string retValue = string.Empty;
try
{
using (var image = System.Drawing.Image.FromFile(path))
{
using (MemoryStream m = new MemoryStream())
{
image.Save(m, ImageFormat.Png);
byte[] imageBytes = m.ToArray();

// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
base64String = String.Concat("data:image/png;base64,", base64String);
retValue = base64String;
}
}
}
catch (Exception ex)
{
log.ErrorFormat("Message : {0}.\n Inner Exception : {1}.\n Exception : {2}.", ex.Message, ex.InnerException, ex);
}
return retValue;
}