zoukankan
html css js c++ java
转:将图片转换成16进制的代码写入文本
using
System.IO;
//
从图片写入文本文件!
private
void
button1_Click(
object
sender, System.EventArgs e)
{
FileStream fs
=
null
;
BinaryReader br
=
null
;
StreamWriter sw
=
null
;
try
{
fs
=
new
FileStream(
"
aa.bmp
"
,FileMode.Open,FileAccess.Read);
br
=
new
BinaryReader(fs);
sw
=
new
StreamWriter(
"
bb.txt
"
);
int
length
=
(
int
)fs.Length;
while
(length
>
0
)
{
byte
tempByte
=
br.ReadByte();
int
tempInt
=
Convert.ToInt32(tempByte);
string
tempStr
=
Convert.ToString(tempInt,
16
);
sw.WriteLine(tempStr);
length
--
;
}
}
catch
(Exception exce)
{
MessageBox.Show(exce.Message);
}
finally
{
sw.Close();
br.Close();
fs.Close();
}
}
//
从文本中读取,并还原成图片!
private
void
button2_Click(
object
sender, System.EventArgs e)
{
FileStream fs
=
null
;
BinaryWriter bw
=
null
;
StreamReader sr
=
null
;
try
{
fs
=
new
FileStream(
"
cc.bmp
"
,FileMode.Create,FileAccess.Write);
bw
=
new
BinaryWriter(fs);
sr
=
new
StreamReader(
"
bb.txt
"
);
while
(sr.Peek()
!=
-
1
)
{
string
tempStr
=
sr.ReadLine();
int
tempInt
=
Convert.ToInt16(tempStr,
16
);
byte
tempByte
=
Convert.ToByte(tempInt);
bw.Write(tempByte);
}
}
catch
(Exception exce)
{
MessageBox.Show(exce.Message);
}
finally
{
sr.Close();
bw.Close();
fs.Close();
}
}
查看全文
相关阅读:
Installing Oracle Database 12c Release 2(12.2) RAC on RHEL7.3 in Silent Mode
周四测试
假期生活
《人月神话》阅读笔记三
《人月神话》阅读笔记二
《人月神话》阅读笔记一
软件进度7
软件进度6
软件进度5
软件进度4
原文地址:https://www.cnblogs.com/wuliang/p/982346.html
最新文章
本周的进度总结
第二周学习进度
暑期第一周学习总结
7/6 学习日志
软件交流大会
多次模糊查询
左右外连接图解
mysql HTTP Status 500 – Internal Server Error
mybatis NumberFormatException
Caused by: org.xml.sax.SAXParseException: 文件提前结束。
热门文章
多数据源切换数据源注入为空问题
[Html] jQuery Grid
[C#][EF] 添加表添加不进来
[C#][Report]Cry
[VS2013]发布网站时修改配置文件
[VS2013]常见异常修正
[转][MVC]更新 dll 后版本不匹配的问题
[转][C#]Combobox 行高
[C#][WebAPI]返回 json
配置网卡绑卡 --RHEL7
Copyright © 2011-2022 走看看