使用SQL server数据库,其中T_Image表中存储图片数据流。
想要把图片二进制数据流展示在页面中。
我的aspx.cs中的代码
protected void Show_Click(object sender, EventArgs e)
{
//string id = Context.Request.QueryString["id"];
SqlConnection conn = new SqlConnection("server=******;uid=sa;pwd=*****;database=******");
SqlCommand cmd = new SqlCommand("select image from Image", conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Context.Response.BinaryWrite((byte[])dr["image"]);
}
dr.Close();
}
页面显示的是二进制数据流,类似这样:
[[[243. 246. 255.]
[243. 246. 255.]
[243. 246. 255.]
...
[243. 246. 255.]
[243. 246. 255.]
[242. 245. 254.]]]
我的数据库里面的就是这样的图片数据,出现这种原因是什么,是我的数据格式错了吗?
假设数据库里的数据是正确的,你需要自己确定一下数据保存的原始文件格式,假设时jpg或png文件之类的,你需要在response里加上响应头,标明你返回的是媒体图片,如