asp.net mvc -如何在标签
本文关键字:img 标签 net mvc asp | 更新日期: 2023-09-27 17:50:28
我正在连接我的HTML字符串现在HTML来自我的DB也有一些图像存储在DB路径和字节…现在我想在html <img>
标签中显示我的图像然后我将其写入doc文件
if (ds.Tables[4].Rows.Count > 0)
{
DataTable Dt_4 = ds.Tables[4];
foreach (DataRow item in Dt_4.Rows)
{
QuestionName += "<br style='page-break-before: always'> <br style='page-break-before: always'>";
QuestionName += "<b><span style='text-decoration:underline'>Question : </span>" + Dt_4.Rows[0]["Q_Num"].ToString() + "</b>";
QuestionName += "<b><span style='padding-left:20px;'>Marks : </span>(" + item["Marks"].ToString() + ")</b>";
QuestionName += item["QuestionName"].ToString();
string imagePath = item["ImagePath"].ToString();
QuestionName += " <div><img src='" + imagePath + "' height='350' width='450'> </div> ";
}
}
当我在服务器上运行时,图像显示正确,但当我从本地机器访问服务器时,它不显示有什么帮助吗?
您可以将图像嵌入为Base64编码字符串,如下所示:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAM0AAAD
NCAMAAAAsYgRbAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5c
cllPAAAABJQTFRF3NSmzMewPxIG//ncJEJsldTou1jHgAAAARBJREFUeNrs2EEK
gCAQBVDLuv+V20dE....." alt="beastie.png">
string MakeImageSrcData(string filename)
{
byte[] filebytes = System.IO.File.ReadAllBytes(filename);
return "data:image/png;base64," +Convert.ToBase64String(filebytes, Base64FormattingOptions.None);
}
<img src="<%=MakeImageSrcData("c:'path'to'my.png") %>" />
https://devio.wordpress.com/2011/01/13/embedding-images-in-html-using-c/http://www.techerator.com/2011/12/how-to-embed-images-directly-into-your-html/