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();
}
}
查看全文
相关阅读:
H5本地存储
小知识(h5 js )
在ubuntu18.04版本安装vscode
函数基本操作
python直接赋值、深浅拷贝实例剖析
collections模块简介
set()集合基本操作
list、tuple、dict内部功能释义
str内部方法释义
int内部方法释义
原文地址:https://www.cnblogs.com/wuliang/p/982346.html
最新文章
作用域与作用域链
伪数组转换为真正的数组
关于javascript中原型和原型链的理解
关于es6中常见的一些方法----对象篇
关于es6中新增的一些方法----数组篇
说一下单页面应用的认识
关于一些常用的linux命令
Angular专题系列之一:初识Anjularjs
浅析node.js
原生js实现一个简单的倒计时功能
热门文章
安格拉小姐
跨域问题浅析
前端工程化浅析
移动端开发浅析
关于angularjs
h5 通过axios下载文件 适合各种文件类型
js实现表单checkbox的单选,全选
css 单行文本居中显示,多行文本左对齐
css三角形
JavaScript的兼容
Copyright © 2011-2022 走看看