我的SQL数据库表中有两列是image类型的
我想在一个页面中显示出这两张图片
代码:
rdr.Read();//SqlDataReader 类型
System.Web.HttpContext.Current.Response.BinaryWrite((byte[])rdr["img1"]);
System.Web.HttpContext.Current.Response.BinaryWrite((byte[])rdr["img2"]);
这样做的话只会显示出img1这一张图片
请问要显示所有的两张图片该怎么来写?

解决方案 »

  1.   

    while(rdr.Read())
      {System.Web.HttpContext.Current.Response.BinaryWrite((byte[])rdr["表名"]);
       }
      

  2.   

    silentwins(原谅我当天不懂得珍惜只知任性...) 
    没看懂我的意思吧
    我rdr.Read()的一个记录集就有2个img类型的数据
      

  3.   

    如果是直接輸出二张图片,建义把两张图片合并到一张图片再输出,不就可以实现了吗?
    方法是,建立一个Bitmap对象,把你两张图片都画到上面去再输出!
      

  4.   

    int bufferSize = 8000000;
    byte[] outbyte = new byte[bufferSize]; //用于读取文件的字节
    long retval ; //每次读取的长度
    long startIndex = 0;  //骗移量
    //…………………………………
    strSql = "select textValue from dbo.tbl_Attachment  where lngAttachmentID="+lngID.ToString(); System.Data.SqlClient.SqlDataReader newDR = this.Sqlca.GetDataReader (strSql);
    try
    {
    while (newDR.Read())
    {
    retval = newDR.GetBytes(0, startIndex, outbyte, 0, bufferSize);
    while (retval == bufferSize)
    {
    Response.BinaryWrite(outbyte);
    startIndex += bufferSize;
    retval =newDR.GetBytes(0, startIndex, outbyte, 0, bufferSize);
    }

    Response.BinaryWrite(outbyte);
    Response.Flush();
    }
    }
    catch(Exception Error)
    {
    Response.Redirect("error.aspx?error="+Server.UrlEncode(Error.Message));
    }
    finally
    {
    newDR.Close();
    newDR = null;
    }这是输出第一列的内容,第二列改一下参数
      

  5.   

    weisunding(鼎鼎)
    怎么样把两张图片合并到一张图片
      

  6.   

    好容易的,说好了,50分都要给我啊,哈哈。
    Image img1 = Image.FromFile("D:\\DING\\My Documents\\My Pictures\\新建文件夹\\1258.gif");
    Image img2 = Image.FromFile("D:\\DING\\My Documents\\My Pictures\\新建文件夹\\2758.jpg"); int h = (img1.Height > img2.Height ) ? img1.Height : img2.Height; Bitmap bmp = new Bitmap(img1.Width + img2.Width, h);
    Graphics g = Graphics.FromImage(bmp);
    g.DrawImage(img1, 0,0);
    g.DrawImage(img2, img1.Width , 0); 到这里,bmp就是两张合并后的图片了
      

  7.   

    合并的做法不可取,如果是显示三张,四张怎么办?
    可以考虑显示图片用一个页面A,取图片数据用一个页面B。
    B页面用Response输出图片。
    A页面上用多个控件显示图片,每个控件的图片路径设为B
      

  8.   

    同意echeng192(想要飞又飞不高)
    合并图片方法好像不是很好
    我这里的实际情况是可能取出1~5张图片
    并不固定
    所以合并图片的方法还是不行的
      

  9.   

    用Image。
    写个页面WebShowPicture显示出图片,Image.ImageUrl = "WebShowPicture.aspx"  ,可以把你读到的图片信息传过去。
    我写了一个,可以参考一下:
    public class WebPictureBox:System.Web.UI.WebControls.Image
    {
    private int _ImageWidth=0;
    private int _ImageHeight=0;
    public WebPictureBox()
    {
    }
    protected override void OnPreRender(EventArgs e)
    {
    if (_ImageHeight!=0&&_ImageWidth!=0)
    {
    this.Height = _ImageHeight;
    this.Width = _ImageWidth;
    }
    }  public void SetPicture(npQuery poQuery ,string pcColumnId,WebRunnerClass poRunner,NpControlObject poCtrlObj)
      {
    if (poRunner!=null&&poQuery!=null&&poQuery.IsOpened
    &&pcColumnId.Trim().Length>0&&poQuery.RecCount>0)
    {
    this.ID= poCtrlObj.Id;
    Byte[] loImageByte  = null;
    object loObj =poQuery.CurrentRow[pcColumnId];
    if (loObj!=null&&loObj is Byte[])
       loImageByte = (Byte[])loObj;
    if (loImageByte!=null)
    {
    poRunner.CurPage.Session[this.ID]=loImageByte;
    this.ImageUrl = "WebShowPicture.aspx?PictureId="+this.ID;
    Object loMap = poQuery.GetImage(pcColumnId);
    if (loMap!=null&&loMap is Bitmap)
    {
    _ImageWidth= ((Bitmap)loMap).Width;
    _ImageHeight = ((Bitmap)loMap).Height;
    }
    }
    }
    }
    }
    显示图片的页面 :private void Page_Load(object sender, System.EventArgs e)
    {
    string lcPictureId = this.Request["PictureId"];
    if (this.Session[lcPictureId]!=null&&this.Session[lcPictureId] is byte[])
    {
    byte[] loImageByte = (byte[])this.Session[lcPictureId]; if (loImageByte!=null)
    {
    Response.Clear();
    Response.ContentType = ".jpg";
    Response.BinaryWrite(loImageByte);
    Response.End();
    }
    }
    }改一下就可以用了。