happyleo12 2017-04-10 08:53 采纳率: 50%
浏览 1703
已采纳

如何把二进制图片读取到image控件

大神帮帮忙看看

 //SQLHelper.cs
 //从数据库中读取image类型图片并且显示到控件上
        public bool ShowImage(string sql, System.Web.UI.WebControls.Image img1)
        {
            SqlConnection imgConn = new SqlConnection(connectionString);
            try
            {
                SqlCommand cmd = new SqlCommand(sql, imgConn);
                imgConn.Open();
                byte[] b = (byte[])cmd.ExecuteScalar();
                if (b.Length > 0)
                {
                    MemoryStream stream = new MemoryStream(b, true);
                    stream.Write(b, 0, b.Length);
                    Image img = Image.FromStream(stream);
                    //img.ImageUrl = new System.Drawing.Bitmap(stream);
                    stream.Close();
                }
                return true;
            }
            catch
            {
                img1 = null;
                return false;
            }
            finally
            {
                imgConn.Close();
            }
        }
//后台
//显示图片
 sp.ShowImage("Select Photo From Description1 Where id='" +this.id.Text + "'", imgphoto);
  • 写回答

2条回答 默认 最新

  • 斯洛文尼亚旅游 2017-04-10 13:42
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?