帮忙看看为什么老是报   Bitmap bt=new Bitmap(ms) 这行异常:参数无效  
代码如下:
数据库中“照片”这列有数据          if (drv["照片"] !=DBNull.Value)//判断数据库中该字段是否为空
                    this.pictureBox1.Image = Teacher.BytesToBitmap((byte[])drv["照片"]);
               else
                 this.pictureBox1.Image = null;
    //转换成bitmap
         public static Bitmap BytesToBitmap(byte[] Bytes)
        {
            MemoryStream ms =new MemoryStream(Bytes);
            Bitmap bt=new Bitmap(ms);   //流转换
            ms.Close();
            return bt;
        }

解决方案 »

  1.   


    using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                {
                    using (BinaryWriter bw = new BinaryWriter(fs))
                    {
                        bw.Write(bytes);
                    }
                }            img = Image.FromFile(fileName, false);这么写试试
      

  2.   

    楼主直接转换成Image试试
    可能数据库中的图片不一定都是BMP格式的图片public static Image BytesToBitmap(byte[] Bytes)
            {
                MemoryStream ms =new MemoryStream(Bytes);
                Image bt=Image.FromStream(ms);  //流转换
                ms.Close();
                return bt;
            }
      

  3.   

    应该是你的byts[]数组没有值
    我按照你的方式做了一下,没有错误
    或者你看一下你的byte[]的长度和里面的数据看一下
    反正是你的byte[]出了问题
      

  4.   

     public static Bitmap BytesToBitmap(byte[] Bytes) 
            { 
                MemoryStream ms =new MemoryStream(Bytes); 
                Bitmap bt=new Bitmap(ms);  //流转换             ms.Close(); 
                return bt; 
            }
    这个地方 有点问题
    Bitmap bt=Image.FromStream(ms);  
    不知道 对不
      

  5.   


     if (drv["照片"] !=DBNull.Value)//判断数据库中该字段是否为空 
                        this.pictureBox1.Image = Teacher.BytesToBitmap((byte[])drv["照片"]); 
    drv是BindingManagerBase绑定的来的当前行用他别的字段数据都可以取出但是就是image字段的取不出,sql server image 不就是对应c# byte[]
      

  6.   

    我那样写是没错的只是ms取得是个空值就是是没传进去byte[],问题在于怎么会传不进?
      

  7.   

    插入断电 看看
    你主要 是读的时候 有点问题 (读数据库的时候)dr["image"]=null
    看一下 你读的时候 是否有问题
    检查 一下
      

  8.   

     Bitmap bt = new Bitmap();
    这样写不对吗?