Want to get data from a database

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 am facing a problem when we hit a string Image oImage = Image.FromStream((Stream)ms);

, this string is executed, but then I get a "Parameter is not valid" exception.

0


a source to share


1 answer


I'm assuming the array imgData

doesn't actually contain a valid image (or whatever it understands how Image.FromStream()

).



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 an "invalid format". If it opens correctly, see this related question .

+1


a source







All Articles