[英]why is my image not appearing
Because the src has to start with "data:{image/format};base64," 由于src必须以“ 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. 为了使用数据url形式的图像,仅在src属性中使用base64编码的图像数据是不够的,还需要使用前缀来告诉浏览器要跟随数据url。
Use: 采用:
<img src="data:image/png;base64,<%= FlagPic %>" alt="Bla"/>
Note that the content type (here image/png) must fit the image graphics format. 请注意,内容类型(此处为image / png)必须适合图像图形格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.