Read MemoryStream - 加载图像\字节并读取它 [英] Read MemoryStream - load image \ byte and read it

查看:62
本文介绍了Read MemoryStream - 加载图像\字节并读取它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

now from file (FileStream) its work

但我不想从文件中执行此操作,因此我需要使用 MemoryStream

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

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

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

最后将字节保存到文件

我尝试这样使用它

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

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

但不工作

如何在内存中再次读取它

how i can do it read it again in memory

谢谢

推荐答案

这会将一个 ByteArray 转换为 MemoryStream 到 Image

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

这篇关于Read MemoryStream - 加载图像\字节并读取它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆