2

Simple as that, how I can convert in VBNET a UnmanagedMemoryStream to Byte-Array?:

Dim bytes() As Byte = My.Resources.AudioFile

Exception:

Value of type 'System.IO.UnmanagedMemoryStream' cannot be converted to '1-dimensional array of Byte'.

2 Answers 2

7

You can convert System.IO.MemoryStream directly to a Byte() Array, by using:

Dim myMemStream As New System.IO.MemoryStream
My.Resources.AudioFile.CopyTo(myMemStream)
Dim myBytes() As Byte = myMemStream.ToArray
Sign up to request clarification or add additional context in comments.

Comments

1

Try this approach. I have not verified it, but it follows something similar as an article from MSDN, with a couple of modifications. http://msdn.microsoft.com/en-us/library/system.io.unmanagedmemorystream.aspx

Dim audioBytes() as Byte
Dim audioStreamReader As System.IO.UnmanagedMemoryStream = CType(My.Resources.AudioFile, System.IO.UnmanagedMemoryStream)
Dim length As Long = audioStreamReader.Length
audioStreamReader.Position = 0
audioStreamReader.Read(bytes, 0, length);
'At this point, audioBytes contains the data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.