Home All Groups Group Topic Archive Search About

Convert Byte() to System.Drawing.Image?

Author
20 Jan 2006 9:35 PM
JackBlack
Using VB.Net (VS.Net 2k3)...

I'm at a bit of an impasse I think...  Is there any way to convert an array
of Byte() into a System.Drawing.Image object without writing the array to a
file, then reading back into the s.d.i object?  Couldn't find anything in
MSDN or by Googling...

Thanks!

Author
20 Jan 2006 9:46 PM
Armin Zingler
"JackBlack" <jackisb***@hotmail.com> schrieb
> Using VB.Net (VS.Net 2k3)...
>
> I'm at a bit of an impasse I think...  Is there any way to convert
> an array of Byte() into a System.Drawing.Image object without
> writing the array to a file, then reading back into the s.d.i
> object?  Couldn't find anything in MSDN or by Googling...


dim stream as System.IO.MemoryStream
dim img as image

stream = new System.IO.MemoryStream(bytearray)
img = image.fromstream(stream)


Armin
Author
20 Jan 2006 9:47 PM
Mattias Sjögren
>I'm at a bit of an impasse I think...  Is there any way to convert an array
>of Byte() into a System.Drawing.Image object without writing the array to a
>file, then reading back into the s.d.i object?

Create a MemoryStream around the byte array and call Image.FromStream.


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
20 Jan 2006 10:02 PM
Herfried K. Wagner [MVP]
"JackBlack" <jackisb***@hotmail.com> schrieb:
> I'm at a bit of an impasse I think...  Is there any way to convert an
> array of Byte() into a System.Drawing.Image object

Create a 'MemoryStream' object, write the byte array to the stream and use
'Image.FromStream' to construct the image.  Note that the stream must be
kept open as long as the 'Image' object exists.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>