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();
}
}
查看全文
相关阅读:
AJAX和DHTML
解析xml的4种方法详解
javascript -window与document 待整理
JavaScript中的shift()、unshift()和pop()函数
JS中如何定义全局变量
j中的substr(start,length)和substring(start,stop)
JS中的唯一容器:数组
typeof()和instanceof的用法区别
JS和DOM的关系
jQuery对象与DOM对象之间的转换方法
原文地址:https://www.cnblogs.com/wuliang/p/982346.html
最新文章
JAVA sleep() & wait()
Java Container ***
任意给定一个正整数N,求一个最小的正整数M(M>1),使得N*M的十进制表示形式里只含有1和0。
【每天一个Linux命令】14. Linux中locate命令的用法
Android常用控件之Fragment仿Android4.0设置界面
python代码中pass的用法
uva 10453
Data Structure(3)——软考阶段学习小结
无线网破解软件|一键式破解无线网|BT17软件包下载[笔记本+软件就行]
Boost环境配置及遇到的问题解决方案
热门文章
HDU 4255 A Famous Grid
Windows之权限的继承性 累加性 优先性 交叉性及四项基本原则
留言本的漏洞挖掘总结
漏洞挖掘分析技术总结
WEB漏洞挖掘技术总结
漏洞挖掘分析技术综述
RSA大会播报 – 2014最佳安全博客提名
nmap速查表v1.0
sqlmap使用帮助文档(1)
新手提权笔记
Copyright © 2011-2022 走看看