在winform中从sqlserver2000 image类型字段读取图片出错,不知道怎么办了,急啊,明天就要交给客户的东西

mycarnation 2006-03-16 11:27:13
在winform中从sqlserver2000 image类型字段读取图片出错,不知道怎么办了,急啊,明天就要交给客户的东西
以下是原代码:
//读取图片
MemoryStream ms = new MemoryStream(((byte[])this.drobj["photo"]));
if(ms.Length !=0)
{
Image image = Image.FromStream(ms,true);
this.picturebox.Image = image;
}
以下是出错信息
未处理的“System.ArgumentException”类型的异常出现在 system.drawing.dll 中。

其他信息: 使用了无效参数。

help me !!!!!!!
...全文
272 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
mycarnation 2006-03-21
  • 打赏
  • 举报
回复
问题已解决,谢谢了!
jietuan 2006-03-20
  • 打赏
  • 举报
回复
byte[] img=(byte[])ds.Tables[0].Rows[0]["Photo"];
MemoryStream a=new MemoryStream(img);
//Image a=new Image();
//Bit
//Bitmap a=new Bitmap(a);
Image b=Image.FromStream(a);
this.pictureBox1.Image=b;
this.pictureBox1.Refresh();
zjonah 2006-03-20
  • 打赏
  • 举报
回复
byte[] myByteArray = (byte[])myPhotoDataSet.Tables[0].Rows[currentPage]["PhotoID"];
if (myByteArray.Length > 0)
{
MemoryStream myStream = new MemoryStream(myByteArray, true);
myStream.Write(myByteArray, 0, myByteArray.Length);

Bitmap FinalImage = new Bitmap(myStream);

photographPictureBox.Image = FinalImage;
Total.Text = "该阀门共有图片" + myPhotoDataSet.Tables[0].Rows.Count + "张,目前显示第" + (currentPage + 1) + "张";
myStream.Close();
}
hy98521 2006-03-20
  • 打赏
  • 举报
回复
是不是原因出在BYTE[] 数组的长度上。 就算是数组也会有个最大的下标限制。
我没有做过这样的事情。 只是猜测
mycarnation 2006-03-20
  • 打赏
  • 举报
回复
谁帮我解决了问题,我给200分
mycarnation 2006-03-20
  • 打赏
  • 举报
回复
都试过了,没用
huoyan999 2006-03-17
  • 打赏
  • 举报
回复
byte[] imgbyte = (byte[])dt.Rows[0]["soh_stamp"];
MemoryStream mstr=new MemoryStream(bytPic);
if(mstr.Length>0)
{
this.pictureBox1.Image =Image.FromStream(mstr);
}
BQY 2006-03-16
  • 打赏
  • 举报
回复
将FromImage的第二个参数设置为false试试。
mycarnation 2006-03-16
  • 打赏
  • 举报
回复
这和我的代码一样啊,没区别
kqh0319 2006-03-16
  • 打赏
  • 举报
回复

try{
}
catch(Exception exxx)
{
System.Console.WriteLine(exxx.message);
}
看看具體是什麼錯誤?
using System.Drawing.Imaging;
要不把這個加進去看看。。


給你個例子參考:
byte[] imgbyte = (byte[])dt.Rows[0]["soh_stamp"];
this.pictureBox1.Image = System.Drawing.Image.FromStream(new System.IO.MemoryStream(imgbyte));

lxjlz 2006-03-16
  • 打赏
  • 举报
回复
沙發
mycarnation 2006-03-16
  • 打赏
  • 举报
回复
试过了,没用

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧