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();
}
}
查看全文
相关阅读:
activiti初学
Python微信跳一跳外挂
Linux下将Mongodb单机升级至副本集
Linux安装Mongodb4.2
Python3 acm基础输入输出
Nginx安装图片模块出错,提示fatal error: curl/curl.h
基于Redis的分布式锁两种实现方式
Nginx常用模块安装命令
Nginx安装Nginx-echo模块
Nginx使用图片处理模块
原文地址:https://www.cnblogs.com/wuliang/p/982346.html
最新文章
最好的前端API备忘单整理
h5软键盘挡住输入框问题解决(android)
vue 格式化银行卡(信用卡)每4位一个符号隔断
React事件绑定几种方法测试
分享几个有意思的css js工具网站
Vue中scoped css和css module比较
不定高元素的高度transition动画实现
Vue.set() this.$set()引发的视图更新思考
mac搭建简单的hls推流服务器遇到的问题(待更新)
python-tkinter学习实例
热门文章
java过滤器、监听器、拦截器机制
2019小结
JVM简介堆中新生代老年代浅析
上线版本20180927
clob字段超过4000转String类型
java中远程http文件上传及file2multipartfile
oracle中listagg()和wmsys.wm_concat()基本用法
IP基础知识与分配实现
关于判空的细节
excel导入及注意事项
Copyright © 2011-2022 走看看