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();
}
}
查看全文
相关阅读:
JavaScript 位运算总结&拾遗
leetcode
leetcode
【位运算经典应用】 寻找那个唯一的数
归并排序 JavaScript 实现
【位运算经典应用】 求二进制逆序
Odoo仪表盘详解
Odoo启动运行参数(script运行参数,不是运行配置文件)
Odoo中的self详解
【Odoo 8开发教程】第二章:Odoo生产环境部署设置
原文地址:https://www.cnblogs.com/wuliang/p/982346.html
最新文章
java中文乱码解决之道(八)-----解决URL中文乱码问题
java中文乱码解决之道(七)-----JSP页面编码过程
java中文乱码解决之道(六)-----javaWeb中的编码解码
java中文乱码解决之道(五)-----java是如何编码解码的
java中文乱码解决之道(四)-----java编码转换过程
java中文乱码解决之道(三)-----编码详情:伟大的创想---Unicode编码
Data URI 应用场景小结
玉伯的一道课后题题解(关于 IEEE 754 双精度浮点型精度损失)
【0.1 + 0.2 = 0.30000000000000004】该怎样理解?
思考题:如何获取当天的农历日期?
热门文章
移动端页面(css)调试之“weinre大法”
Javascript Date
让 HTML5 来为你定位
如何使用 UC浏览器开发者版 进行移动端调试
Web Worker 是什么鬼?
为什么Javascript中的基本类型能调用方法?
二叉树三种遍历的递归和迭代解法
Jump Game 的三种思路
树状数组的三大应用
神奇的树状数组
Copyright © 2011-2022 走看看