Home
> Uncategorized > Load Image as Base64 string
Load Image as Base64 string
In JavaScript you can display an image like this <img src=”data:image/jpg;base64,…”> where “…” is the base64 encoded version of the image. Here is some C# Code that can convert an image on-disk to this Base64 string format
FileInfo fi = new FileInfo(strFileName);
FileStream fs = new FileStream(strFileName, FileMode.Open, FileAccess.Read,FileShare.None);
byte[] rawData = new byte[fi.Length];
fs.Read(rawData, 0, (int)fi.Length);
string strBase64 = Convert.ToBase64String(rawData);
Response.Write("data:image/jpg;base64," + strBase64);
fs.Close();
Categories: Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback