本帖最后由 gaochenfeng2008 于 2009-10-09 16:16:06 编辑

解决方案 »

  1.   

    先把二进制的代码转换成 图片格式
    这里有个简单的列子
     OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Server.MapPath(@"~\App_Data\DataBase.aspx"));
                try
                {
                    con.Open();
                    OleDbCommand com = new OleDbCommand("select * from Picture where Pic_ID=" + Request["Pic_ID"] + "", con);
                    OleDbDataReader dr = com.ExecuteReader();
                    dr.Read();
                    MemoryStream ms = new MemoryStream((Byte[])dr["Pic"]);
                    Bitmap image = new Bitmap(ms);
                    dr.Close();
                    //Response.ContentType = "image/Gif";
                    Response.BinaryWrite(ms.ToArray());
                    // Image1.ImageUrl = "~/display9.jpg";
                }
                catch (Exception error)
                {
                    //Label1.Text = "处理失败!原因为:" + error.ToString();
                }
                finally
                {
                    con.Close();
                }
      

  2.   

    一般是在.ashx里输出图片信息.ShowPic.ashx, 在GridView的<TemplateField>内<img src="ShowPic.ashx?Key='<%# Eval("主关键字段名") %>" alt="" /><%@ WebHandler Language="C#" Class="ShowPic" %>using System;
    using System.Web;
    using System.IO;
    using System.Data.SqlClient;public class ShowPic : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) {
            int 参数值 = Convert.ToInt32(context.Request.QueryString["Key"]);        using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["连接字符串名"].ConnectionString;
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "select 图片字段名 from 表名 where 主关键字段名=@参数";
                cmd.Parameters.AddWithValue("@参数", 参数值);            conn.Open();            object result = cmd.ExecuteScalar();            byte[] byts = (byte[])result;
                context.Response.ContentType = "image/jpeg";
                context.Response.BinaryWrite(byts);
                
            }
            
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }
    }