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
Vra
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'.
Oplossing
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
Ander wenke
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.