【问题标题】:Want to retrieve data from database想要从数据库中检索数据
【发布时间】:2009-05-20 09:22:09
【问题描述】:
byte[] imageData = null;
long byteSize = 0;
byteSize = _reader.GetBytes(_reader.GetOrdinal(sFieldName), 0, null, 0, 0);

imageData = new byte[byteSize];
long bytesread = 0;
int curpos = 0, chunkSize = 500;
while (bytesread < byteSize)
{
    // chunkSize is an arbitrary application defined value 
    bytesread += _reader.GetBytes(_reader.GetOrdinal(sFieldName), curpos, imageData, curpos, chunkSize);
    curpos += chunkSize;
}

byte[] imgData = imageData;

MemoryStream ms = new MemoryStream(imgData);
Image oImage = Image.FromStream((Stream)ms);
return oImage;

当我们点击Image oImage = Image.FromStream((Stream)ms);这行时遇到问题,这行被执行,但之后我得到一个异常“参数无效。”

【问题讨论】:

标签: c# .net


【解决方案1】:

我猜imgData 数组实际上并不包含有效图像(或者至少Image.FromStream() 可以理解的图像)。

尝试根据您认为的数据检查数据。您也可以尝试将流保存到文件并以这种方式打开它 - 我猜它会因为“无效格式”而失败。如果打开正确,请查看this related question

【讨论】:

    猜你喜欢
    • 2013-07-05
    • 1970-01-01
    • 2019-11-19
    • 2016-08-03
    • 2021-02-11
    • 2013-01-01
    相关资源
    最近更新 更多