how to Convert image to base64 in asp.net

Use below code to convert image to base 64.

public string ConvertImageToBase64(string imgSrc)
{
try
{
var webClient = new WebClient();
var imageBytes = webClient.DownloadData(imgSrc);
return “data:image/png;base64,” + Convert.ToBase64String(imageBytes);
}
catch
{
return string.Empty;
}
}

SHARE THIS

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.