Read MemoryStream - 加载图像\字节并读取它

发布于 2025-01-07 09:54:49 字数 1330 浏览 0 评论 0原文

好的,我有一个在其中绑定信息的图像,我想

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

最后将字节保存到文件

我尝试像这样使用它

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

但不是工作

我该怎么做,在记忆中再读一遍,

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热情消退 2025-01-14 09:54:49

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文