用的是绑定的数据源 ,想把图片从数据库里面直接读出来,显示到picturebox控件,不知道哪里出的问题显示不出来,也不报错。
private void categoriesBindingSource_CurrentChanged(object sender, EventArgs e)
        {
            if (_imageBitmap != null)
            {
                _imageBitmap.Dispose();
            }
           DataRowView rowView = (DataRowView)categoriesBindingSource.Current;
            NorthwindDataSet.CategoriesRow row = (NorthwindDataSet.CategoriesRow)rowView.Row;
                    
            byte[] b = (byte[])row.Picture;            if (b.Length >0)
               {
              System.IO.MemoryStream stream = new System.IO.MemoryStream(b, true);
              stream.Write(b, 0, b.Length);
              pictureBox1.Image = new Bitmap(stream);
              stream.Close();
             }
       
        }
    }

解决方案 »

  1.   

    stream.Write(b, 0, b.Length); 
    去掉试试
      

  2.   

    你把byte保存成文件看看..能不能用看图工具打开..可能你的byte[]损坏了.
      

  3.   

    图片显示期间, 图片所在的流不可关闭, 整成类的成员变量试试,gdi+ 对图片的描绘需要那个流
      

  4.   

    MemoryStream MS = new MemoryStream((Byte[])row.Picture);
    Image Photo = Image.FromStream(MS, true);
    pictureBox1.Image = Photo;
      

  5.   

    “System.Drawing.Image”并不包含“FromStream”的定义 Image对象是哪里,我这段程序用在 WM5.0上面在。
      

  6.   

    你确定你的 MemoryStream 没有关闭把
      

  7.   

    //stream.Close();
    这段代码我注释了,试了的
      

  8.   

    那你还是把byte[]保存成文件看看..或则你取出来时候少了什么
      

  9.   

    我写了一个用于绑定数据库字段的图片控件, 从 PictureBox 派生的,
    这个类有个 流成员    Stream _baseStream; // 图片的基地流    // 将数据库来的字节流转换成图片,
        // 这里转换成功后直接赋值给 this.Image
        Image BytesToImage(byte[] bytes)
        {
          Image image = null;
          _baseStream = new MemoryStream(bytes);
          try
          {
            image = System.Drawing.Image.FromStream(_baseStream);
          }
          catch (ArgumentException)
          {
          }
          if (null == image)
          {
            // 注意这里在何种情况下关闭, 销毁 流对象
            _baseStream.Dispose();
            _baseStream = null;
          }
          return image;
        }