2

就这么简单,我如何在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'.
4

2 回答 2

6

您可以使用以下方法System.IO.MemoryStream直接转换为Byte()数组:

Dim myMemStream As New System.IO.MemoryStream
My.Resources.AudioFile.CopyTo(myMemStream)
Dim myBytes() As Byte = myMemStream.ToArray
于 2013-07-13T07:49:54.780 回答
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.
于 2013-07-13T07:38:10.550 回答