0
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."

1800 INFORMATION
  • 131,367
  • 29
  • 160
  • 239
Shamim
  • 359
  • 4
  • 12
  • 25
  • Perhaps it would make sense to show us the line that actually raises the exception and its surrounding code. IOW the code that calls the function you've shown us so far. – AnthonyWJones May 20 '09 at 09:32
  • Already asked today: http://stackoverflow.com/questions/886465/image-retrive/ – Fredrik Mörk May 20 '09 at 09:51

1 Answers1

1

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.

Community
  • 1
  • 1
lc.
  • 113,939
  • 20
  • 158
  • 187