我正在尝试将从richeditDocument 生成的内存流转换为字节数组。代码如下:
Public Sub saveAsTemplate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ms As MemoryStream = New MemoryStream()
richEditControl1.SaveDocument(ms, DocumentFormat.Rtf)
GetStreamAsByteArray(ms)
MessageBox.Show("save")
End Sub
Private Function GetStreamAsByteArray(ByVal stream As MemoryStream) As Byte()
Dim streamLength As Integer = Convert.ToInt32(stream.Length)
Dim fileData As Byte() = New Byte(streamLength) {}
' Read the file into a byte array
stream.Read(fileData, 0, streamLength)
stream.Flush()
stream.Close()
Return fileData
End Function
流是生成的,因为我可以获得流长度,但是最终的位数组仅由 0 组成,使其无效。我怎样才能得到它的正确字节数组?