如此简单,如何将 VBNET UnmanagedMemoryStream 转换为 Byte-Array :
Dim bytes() As Byte = My.Resources.AudioFile
例外:
Value of type 'System.IO.UnmanagedMemoryStream' cannot be converted to '1-dimensional array of Byte'.
答案 0 :(得分:5)
您可以使用以下内容将System.IO.MemoryStream
直接转换为Byte()
数组:
Dim myMemStream As New System.IO.MemoryStream
My.Resources.AudioFile.CopyTo(myMemStream)
Dim myBytes() As Byte = myMemStream.ToArray
答案 1 :(得分:1)
尝试这种方法。我还没有验证它,但它跟MSDN上的一篇文章类似,有一些修改。 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.