Because the src has to start with "data:{image/format};base64,"
Try this:
public string FlagPic
{
get
{
using (System.IO.MemoryStream m = new System.IO.MemoryStream())
{
ClassLibrary1.Resource1.flag.Save(m, ClassLibrary1.Resource1.flag.RawFormat);
byte[] imageBytes = m.ToArray();
base64Image = System.Convert.ToBase64String(imageBytes);
return String.Format("data:{1};base64,{0}", base64Image, ClassLibrary1.Resource1.flag.RawFormat);
}
}
}
In order to use an image in the form of a data url, it is not enough to use the base64 encoded image data in the src attribute, you also need to use a prefix to tell the browser that a data url is following.
Use:
<img src="data:image/png;base64,<%= FlagPic %>" alt="Bla"/>
Note that the content type (here image/png) must fit the image graphics format.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.