tags:

views:

62

answers:

1
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;

I face problem when we hit the line Image oImage = Image.FromStream((Stream)ms); this line is executed, but afterwards I get an exception "Parameter is not valid."

+1  A: 

I'm guessing the imgData array doesn't actually contain a valid image (or one that Image.FromStream() understands at least).

Try checking the data against what you think it should be. You can also try saving the stream to a file and opening it that way - I'm guessing it will fail as "invalid format". If it opens correctly, have a look at this related question.

lc