BorisAro

Hello!
I have an OLE Object in my table, that may be jpg, doc, xml file.
In case of jpg I'd like to show it (VS2005 Visual basic).
I did next (not full code):

Dim ms AsNew MemoryStream()
Dim reader As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.SequentialAccess )
reader.Read()
retval = reader.GetBytes(0, 0, outbyte, 0, bufferSize)
ms.Write(outbyte, 0, retval)
ms.Seek(0, SeekOrigin.Begin)
curImage = Image.FromStream(ms
)----> error "Parameter is not valid."

I do not see the fault. Please help



Re: Visual Basic IDE Image.FromStream(ms)----> error "Parameter is not valid." Help!!!!

Jared Parsons MSFT

It looks like the problem is that the stream isn't pointing to a valid image.






Re: Visual Basic IDE Image.FromStream(ms)----> error "Parameter is not valid." Help!!!!

sanjeet.blr

Hi ,you r getting error FromStream(ms) , previously i also got same Exception.
I think when u converting string to byte and passing MemoryStream and after that
FromStream, there is some invalid characters in that String which cant converted
to byte array properly.

So in place of String use Hex String and convert that String to Byte array.

How to convert HexString to byte array see this link

http://www.codeproject.com/csharp/hexencoding.asp


byte[] byteImg = HexEncoding.GetBytes(strImage, out discarded);
MemoryStream streamBitmap = new MemoryStream(byteImg);
pictureBox1.Image = Image.FromStream((Stream)streamBitmap);

this is my code and working fine. Here strImage is a HexString.
and further for help mail me sanjeet.gupta@gmail.com