【问题标题】:Read MemoryStream - load image \ byte and read it读取 MemoryStream - 加载图像\字节并读取它
【发布时间】:2012-02-21 20:26:27
【问题描述】:

好的,我有图像,我在其中绑定了信息,我想阅读信息

现在从文件 (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()

但不工作

如何才能在内存中再次读取它

谢谢

【问题讨论】:

    标签: vb.net memorystream


    【解决方案1】:

    这会将 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      • 2014-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多