vb.net字节数组到文本文件并返回 [英] vb.net Byte Array to text file and back
问题描述
大家好,
我正在尝试将图像保存在文本文件中.
这是我在做什么:
Hello Everyone,
I am trying to save an image in a text file.
here is what I am doing:
Dim writer As New System.IO.StreamWriter("D:\Object.txt", True)
Dim temp() As Byte = convertImageToBytes(i.setBitmap)
Dim str = System.Text.Encoding.ASCII.GetString(temp)
writer.WriteLine(str)
我得到了温度(字节数组)的计数并记下来.
接下来,当我想读取该数组时,我使用:
I get the count of the temp (byte array) and note it down.
next when I want to read that array, i use:
Dim byteArray() As Byte
byteArray = System.Text.Encoding.ASCII.GetBytes(reader.ReadLine.ToString)
Dim b As Bitmap = imgConverter.ConvertFrom(byteArray)
这里的数目也一样.
但是当我将字节数组转换为图像时,我得到了一个大十字架!!!
可能是什么问题?
另外,我想在对象的属性中输入名称,位置等文字.
例如:
名称:Name1
X:500
Y:50
尺码X:200
尺码Y:600
BYTE ARRAY HERE
zVal:5
等
有人可以帮我将图像数据写入文本文件吗?
在此先感谢!!!
here also the count is same.
but when I convert the byte array to image, I get a Big Cross!!!
What could be the problem?
Also, I would like to put in my object''s properties in text like name, location, etc.
eg:
Name: Name1
X:500
Y:50
SizeX:200
SizeY:600
BYTE ARRAY HERE
zVal:5
etc
Can someone help me in writing the image data to a text file?
Thanks in Advance!!!
推荐答案
请使用 ^ ]的Write(Byte [])方法写入图像,反之 BinaryReader [^ ]的ReadBytes(int count)方法将其读回.在这种情况下,将字节数组编码为ASCII并不是您真正想要的.
问候,
—曼弗雷德(Manfred)
Please use the BinaryWriter[^]''s Write(Byte[]) method to write the image and conversely the BinaryReader[^]''s ReadBytes(int count) method to read it back in. Encoding a byte array into ASCII is not really what you want to do in this case.
Regards,
— Manfred
这篇关于vb.net字节数组到文本文件并返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!