相关文章推荐
刚分手的甘蔗  ·  Java 中使用 JSON - 知乎·  1 年前    · 
//读取图片信息并转换成16进制字符串数据
private void button1_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream("d:\\Blue hills.jpg", FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
StreamWriter sw = new StreamWriter("d:\\bb.txt");
int length = (int)fs.Length;
while (length > 0)
{
byte tempByte = br.ReadByte();
string tempStr = Convert.ToString(tempByte, 16);
sw.WriteLine(tempStr);
length--;
}
fs.Close();
br.Close();
sw.Close();
}
//获得16进制图片字符串信息并转换成图片信息
private void button2_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream("D:\\cc.jpg", FileMode.Create, FileAccess.Write); //在D盘创建cc.jpg图片
BinaryWriter bw = new BinaryWriter(fs);
StreamReader sr =new StreamReader("D:\\bb.txt");         //打开你的16进制的txt
while (sr.Peek() != -1)
{
string tempStr = sr.ReadLine();
byte tempByte = Convert.ToByte(tempStr,16);
bw.Write(tempByte);
}
fs.Close();
bw.Close();
sr.Close();
}
//读取图片信息并转换成16进制字符串数据        private void button1_Click(object sender, EventArgs e)        {            FileStream fs = new FileStream("d:\\Blue hills.jpg", FileMode.Open, FileAccess.Read);