【发布时间】:2015-07-13 17:33:45
【问题描述】:
我从数据库中获取二进制字节并将它们转换为 png 图像并将它们保存在项目的 /Images 文件夹中并通过标签显示它们。这些文件是在开发人员环境中创建和使用的,但一旦我发布它,只有文件会在 images 文件夹中创建,但不会被读取或显示在 IMG 标记中。
public string Image_Binary(string pic_id)
{
var imagepath=ConfigurationManager.AppSettings["ImagePath"];
string picstring;
string pid = pic_id;
string path = imagepath+ pid + ".Png";
if (pid != null && pid != "")
{
if (File.Exists(Server.MapPath(path)))
{
picstring = imagepath + pid + ".Png";
}
else
{
DataSet picds = DB.fetchdata("select PictureBinary FROM Picture where Id=" + pic_id);
byte[] picbin = (byte[])picds.Tables[0].Rows[0][0];
ImageConverter ic = new ImageConverter();
System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(picbin);
img.Save(Server.MapPath(imagepath + pid + ".Png"), System.Drawing.Imaging.ImageFormat.Png);
picstring = imagepath + pid + ".Png";
}
}
else
{
//picstring = null;
picstring = "#";
}
return picstring;
}
Web.config 条目
<appSettings>
<add key="ImagePath" value="~/ProductImages/"
</appSettings>
【问题讨论】:
-
右击你的页面,点击检查元素并查看文件路径,你也应该在控制台出现404错误