Created
May 19, 2021 21:11
-
-
Save ozansulukpinar/4e59de8df0fe1ce828ac29a1b05a2c1c to your computer and use it in GitHub Desktop.
Get the image from URL to convert to base64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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