之前在http://www.cnblogs.com/JsonZhangAA/p/5568575.html博文中是利用的image控件来显示的二进制流图片,我现在想的是能
通过普通的这种形式来显示我的二进制流图片吗?必须可以(?▽?),就是写法稍微麻烦了一点,img要写成这个样子:
,对你看的没错,它的地址指向了一个aspx页面,这个页面有个奇特之处,
就是我们新建后,不用写任何前台代码,WebForm1前后台代码如下:
前台:
后台代码:
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;using显示爬虫所爬的数据库中的图片.Models;namespace显示爬虫所爬的数据库中的图片
{public partial classWebForm1 : System.Web.UI.Page
{protected void Page_Load(objectsender, EventArgs e)
{int id = int.Parse(Request["id"].ToString());
DataClasses1DataContext db= newDataClasses1DataContext();
Response.ContentType= "application/binary;";//这个地方图片可以从数据库中读取二进制图片//byte[] img = DBHelper.ReadImg();
byte[] img = db.pictureUrl.Where(p=>p.Id==id).First().pictureUrl1.ToArray();
Response.BinaryWrite(img);
Response.Flush();
Response.End();
}
}
}
我们主页面的前后台代码如下:
前台:
" %>
Index" />