Dim arr As New ArrayList()
arr.Add("AAA")
arr.Add("BBB")
arr.Add("CCC")
Dim byteArray As Byte() = New Byte(2) {}
For i As Integer = 0 To arr.Count - 1
byteArray = DirectCast(arr(i), Byte())
Next
'Read byteArray to stream
Dim stream As New System.IO.MemoryStream(byteArray)
aspd
Member
38 Points
525 Posts
how do i read a byte array into a stream?
Oct 06, 2008 03:26 PM|LINK
Hi All.
I have a method that returns an image in byte array form. I need to take this byte array and read it into a stream. Is this possible? If so, how?
Appreciated.
Thanks in advance.
vinz
All-Star
127087 Points
17946 Posts
MVP
Re: how do i read a byte array into a stream?
Oct 06, 2008 04:14 PM|LINK
Have a look at:
http://www.yoda.arachsys.com/csharp/readbinary.html
http://www.dotnet-friends.com/articles/asp/artinasp03e650de-2b15-4fb1-9bdb-aad1a1e5ac5c.aspx
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
aspd
Member
38 Points
525 Posts
Re: how do i read a byte array into a stream?
Oct 06, 2008 04:27 PM|LINK
basically, the method returns a system.array object
the data is like :
(1) = 255
(2) = 216
(3) = 255
etc etc
when i try to cast it put it in a memory stream like this:
Dim str As System.IO.MemoryStream = New System.IO.MemoryStream(arr)
it gives me an error:
System.InvalidCastException = {"Unable to cast object of type 'System.Byte[*]' to type 'System.Byte[]'."}
Any ideas?
vinz
All-Star
127087 Points
17946 Posts
MVP
Re: how do i read a byte array into a stream?
Oct 06, 2008 05:19 PM|LINK
You should pass by byteArray to stream...
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
aspd
Member
38 Points
525 Posts
Re: how do i read a byte array into a stream?
Oct 06, 2008 05:41 PM|LINK
how?
budugu
All-Star
41134 Points
6022 Posts
Re: how do i read a byte array into a stream?
Oct 06, 2008 06:51 PM|LINK
It should be some thing like this..
"Don't be afraid to be wrong; otherwise you'll never be right."
vinz
All-Star
127087 Points
17946 Posts
MVP
Re: how do i read a byte array into a stream?
Oct 06, 2008 07:32 PM|LINK
Try this example below using ArrayList..
Dim arr As New ArrayList() arr.Add("AAA") arr.Add("BBB") arr.Add("CCC") Dim byteArray As Byte() = New Byte(2) {} For i As Integer = 0 To arr.Count - 1 byteArray = DirectCast(arr(i), Byte()) Next 'Read byteArray to stream Dim stream As New System.IO.MemoryStream(byteArray)MessageBox Controls for WebForms | Blog | Twitter | Linkedin