日期:2014-05-17  浏览次数:20466 次

image控件显示二进制图片
有个image控件 数据库取到的二进制图片 byte[] imagebytes = null; 
imagebytes =(byte[])sdr[4]; 
Response.BinaryWrite(imagebytes);可以在页面看到图片 
如何将他显示在页面中的image控件中。

------解决方案--------------------
<img src="show.aspx?id=x" />
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();
  }

------解决方案--------------------
1楼的确是在控件中显示的,楼主你试试
------解决方案--------------------
image控件要显示图片,要指定imageUrl


------解决方案--------------------
引用:
我想用VS自带的image控件
<asp:Image ID="Image1" runat="server" Height="177px" Width="159px"/>
具体要怎么做?
图片的二进制数据是 imagebytes


为何不直接保存路径呢?

吧数据库里的二进制取出来转换图片保存 文件夹下  获取路径 存入数据库

image直接访问路径。