Read MemoryStream - load image \ byte and read it

为君一笑 提交于 2019-12-23 03:26:33

问题


ok i have image that i bind info in it and i want to read the info

now from file (FileStream) its work

but i want to do it not from file so i need to use MemoryStream

here the example that work and how i do it now how i make it work with MemoryStream (with byte = My.Resources or 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

at the end save the byte to file

i try to use it like this

Using FS As New IO.MemoryStream(image) 'image = byte()

but not work

how i can do it read it again in memory

thanks


回答1:


This will convert a ByteArray to MemoryStream to 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


来源:https://stackoverflow.com/questions/9384636/read-memorystream-load-image-byte-and-read-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!