帮忙看看为什么老是报 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;
}
代码如下:
数据库中“照片”这列有数据 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;
}
using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
bw.Write(bytes);
}
} img = Image.FromFile(fileName, false);这么写试试
可能数据库中的图片不一定都是BMP格式的图片public static Image BytesToBitmap(byte[] Bytes)
{
MemoryStream ms =new MemoryStream(Bytes);
Image bt=Image.FromStream(ms); //流转换
ms.Close();
return bt;
}
我按照你的方式做了一下,没有错误
或者你看一下你的byte[]的长度和里面的数据看一下
反正是你的byte[]出了问题
{
MemoryStream ms =new MemoryStream(Bytes);
Bitmap bt=new Bitmap(ms); //流转换 ms.Close();
return bt;
}
这个地方 有点问题
Bitmap bt=Image.FromStream(ms);
不知道 对不
if (drv["照片"] !=DBNull.Value)//判断数据库中该字段是否为空
this.pictureBox1.Image = Teacher.BytesToBitmap((byte[])drv["照片"]);
drv是BindingManagerBase绑定的来的当前行用他别的字段数据都可以取出但是就是image字段的取不出,sql server image 不就是对应c# byte[]
你主要 是读的时候 有点问题 (读数据库的时候)dr["image"]=null
看一下 你读的时候 是否有问题
检查 一下
这样写不对吗?