日期:2014-05-18 浏览次数:20984 次
if (openFileDialog1.ShowDialog()==DialogResult.OK  )
{
Stream ms=openFileDialog1.OpenFile ();
pictureBox1.Image =Image.FromStream(ms) ; //正常
byte[] imgbytes=new byte[ms.Length ] ;
ms.Read(imgbytes,0,(Int32)ms.Length);  
Stream  msview = new MemoryStream(imgbytes);  
pictureBox2.Image =Image.FromStream(msview) ; //出错:“其他信息: 使用了无效参数。”
if(openFileDialog1.ShowDialog()==DialogResult.OK)
            {
                System.IO.FileStream Fs =new System.IO.FileStream(openFileDialog1.FileName,System.IO.FileMode.Open);
                byte[] imgbytes =new byte[Fs.Length];
                Fs.Read(imgbytes,0,imgbytes.Length);
                Fs.Close();
                System.IO.Stream  msview = new System.IO.MemoryStream(imgbytes);  
                pictureBox1.Image =Image.FromStream(msview);
            }
------解决方案--------------------
数据库读取:
  foreach (DataRow ddr in ds.Tables[0].Rows)
               {
                   if (ddr["图片"] != DBNull.Value)
                   {
                       byte[] bytes = (byte[])ddr["图片"];
                       MemoryStream buf = new MemoryStream(bytes);
                       Image image = Image.FromStream(buf, true);
                       this.pictureBox1.Image = image;
                   }
                   else
                       this.pictureBox1.Image = null;
               }