读取MemoryStream - 加载image \ byte并读取它

时间:2012-02-21 20:26:28

标签: vb.net memorystream

好的我有图像,我绑定信息,我想阅读信息

现在从文件(FileStream)开始工作

但我想这样做不是来自文件所以我需要使用MemoryStream

这里是工作的示例以及我现在如何使用MemoryStream(使用byte = My.Resources或PictureBox1.image)使用它

Using FS As New IO.FileStream(image, IO.FileMode.Open)
            FS.Seek(0, IO.SeekOrigin.End)
            While Not FS.ReadByte = Asc("|")
                FS.Position -= 2
            End While
            Dim s As String = Nothing
            While Not FS.Position = FS.Length - 4
                s &= Chr(FS.ReadByte.ToString)
            End While
            Dim Ext As String = Nothing
            FS.Seek(0, IO.SeekOrigin.End)
            While Not FS.ReadByte = Asc("*")
                FS.Position -= 2
            End While
            While Not FS.Position = FS.Length
                Ext &= Chr(FS.ReadByte.ToString)
            End While
            FS.Seek(FS.Length - ((s.Length + s) + 5), IO.SeekOrigin.Begin)

            While Not FS.Position = FS.Length - (s.Length + 5)

                Dim Data As Byte() = New Byte(FS.Position) {}
                FS.Read(Data, 0, Data.Length)
                FS.Close()

            End While

最后将字节保存到文件

我尝试像这样使用它

使用FS作为新IO.MemoryStream(image)'image = byte()

但没有工作

我怎么能在内存中再读一遍

感谢

1 个答案:

答案 0 :(得分:3)

这会将ByteArray转换为MemoryStream为Image

  Public Function byteArrayToImage(byteArrayIn As Byte()) As Image
          Dim ms As New MemoryStream(byteArrayIn)
          Dim returnImage As Image = Image.FromStream(ms)
      Return returnImage
  End Function