Skip to content

Instantly share code, notes, and snippets.

@ozansulukpinar
Created May 19, 2021 21:11
Show Gist options
  • Save ozansulukpinar/4e59de8df0fe1ce828ac29a1b05a2c1c to your computer and use it in GitHub Desktop.
Save ozansulukpinar/4e59de8df0fe1ce828ac29a1b05a2c1c to your computer and use it in GitHub Desktop.
Get the image from URL to convert to base64
using System.Net;
private string GetBase64StringForImage(string url)
{
string base64string = "";
if (url != null)
{
try
{
var image = new WebClient().DownloadData(url);
base64string = Convert.ToBase64String(image);
base64string = "data:image/png;base64," + base64string;
}
catch (Exception)
{
return base64string;
}
}
return base64string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment