Image类型的转换问题 我现在存储一张图片到数据库,类型是image类型,如何把image类型的数据显示在页面上 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 SqlDataReader dr = command.ExecuteReader(); if(dr.Read()) { FileInfo fi = new FileInfo("temp"); FileStream myStream=fi.Open(FileMode.Create); byte[] mydata=((byte[])dr["imgdata"]); foreach(byte a in mydata) { myStream.WriteByte(a); } myStream.Close(); Image myImage=Image.FromFile("temp") ; pic1.Image=myImage; pic1.Refresh();dr.Close ();pc1是页面上的IMAGE控件 Response.BinaryWrite((byte[])dt.Rows[0]["img"]) 把数据转换成图片,再将转换的图片保存为实体文件.将IMG URL指向该实体文件所在地址. 我的回复你试过吗?SqlDataReader dr = command.ExecuteReader();就是从数据库里读出来的imgdata是字段名。 <img src="a.aspx?id=x" />show.aspxprivate void Page_Load(object sender, System.EventArgs e) { string strID = Request.QueryString["id"]; string sqlstr = "select photo from Tb where id=@id"; SqlConnection myConnection = new SqlConnection(connstr); SqlCommand myCommand = new SqlCommand(sqlstr, myConnection); myCommand.AddWithValue("@id",strID ) try { myConnection.Open(); SqlDataReader dr= myCommand.ExecuteReader(CommandBehavior.CloseConnection); if(dr.Read()) { Response.Clear(); Response.ContentType = "image/gif"; Response.BinaryWrite((byte[])dr["photo"]); } myConnection.Close(); } catch (SqlException ex) { } Response.End(); arrayList怎么取数组里的值? 手机版网页图片问题。在线等 asp.net 中 想在后台弹出一个确认 提示框? 函数无法使用当使用了AJAX的updatepanel 存储过程 & SQL语句???谢谢啦==在线等…… 什么时候用接口呢? 新手巨菜的问题,关于DropDownList 有点急手的问题,在线等! Server Error in '/' Application. 错误如何解决 页面之间用汉字做为传递的参数又问题,有解决的办法么?????急!!!!!!! 关于跨框架的顯示導航菜單的問題? xml 数据如何导入到相对应xsd生成的实体类中去?
if(dr.Read())
{
FileInfo fi = new FileInfo("temp");
FileStream myStream=fi.Open(FileMode.Create);
byte[] mydata=((byte[])dr["imgdata"]);
foreach(byte a in mydata)
{
myStream.WriteByte(a);
}
myStream.Close();
Image myImage=Image.FromFile("temp") ;
pic1.Image=myImage;
pic1.Refresh();
dr.Close ();pc1是页面上的IMAGE控件
我的回复你试过吗?
SqlDataReader dr = command.ExecuteReader();就是从数据库里读出来的
imgdata是字段名。
show.aspx
private void Page_Load(object sender, System.EventArgs e)
{
string strID = Request.QueryString["id"];
string sqlstr = "select photo from Tb where id=@id";
SqlConnection myConnection = new SqlConnection(connstr);
SqlCommand myCommand = new SqlCommand(sqlstr, myConnection);
myCommand.AddWithValue("@id",strID )
try
{
myConnection.Open();
SqlDataReader dr= myCommand.ExecuteReader(CommandBehavior.CloseConnection);
if(dr.Read())
{
Response.Clear();
Response.ContentType = "image/gif";
Response.BinaryWrite((byte[])dr["photo"]);
}
myConnection.Close();
}
catch (SqlException ex)
{
}
Response.End();