【发布时间】:2014-01-19 11:23:13
【问题描述】:
我有一个代码,我想从图像中获取流并将内存流转换为字符串数组并存储在变量中。但我的问题是我也想从字符串变量中获取图像并在图片框上绘制。
如果我这样使用 PictureBox1.Image = image.FromStream(memoryStream) 我可以在图片框上打印图片。但这不是我的需要。我只想从文件中获取图像流并将流转换为文本并将其存储到某个字符串变量中,我想再次使用字符串变量并将其转换为流以在图片框上打印图像。
这是我的代码。(Vb Express 2008)
Public Function ImageConversion(ByVal image As System.Drawing.Image) As String
If image Is Nothing Then Return ""
Dim memoryStream As System.IO.MemoryStream = New System.IO.MemoryStream
image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Gif)
Dim value As String = ""
For intCnt As Integer = 0 To memoryStream.ToArray.Length - 1
value = value & memoryStream.ToArray(intCnt) & " "
Next
Dim strAsBytes() As Byte = New System.Text.UTF8Encoding().GetBytes(value)
Dim ms As New System.IO.MemoryStream(strAsBytes)
PictureBox1.Image = image.FromStream(ms)
Return value
End Function
【问题讨论】:
-
我只是好奇-为什么需要将图像转换/加载到内存流才能在图片框中显示它,而不能直接将图像保存到文件系统然后使用标准方法加载它?
-
感谢您的回复。但我知道标准方法。我只想在富文本框中加载字符串变量。我得到像“71 70 56 255 240 15 ....”(取决于图片)rgb值的地方,我想手动更改值只是为了实验目的并重新打包到图像中,我想看看变化. :)
标签: vb.net memorystream