zoukankan
html css js c++ java
用 XML 文件持久化和恢复图片信息
随便写写的一个例子:
//
保存图片到 XML 文件
private
void
Form1_Load(
object
sender, System.EventArgs e)
{
Image img
=
Image.FromFile(
@"
E:\MyDocs\My Pictures\样品.jpg
"
);
System.IO.MemoryStream stream
=
new
System.IO.MemoryStream();
img.Save(stream, ImageFormat.Jpeg);
byte
[] b
=
stream.GetBuffer();
string
s
=
Convert.ToBase64String(b);
XmlDocument doc
=
new
XmlDocument();
doc.AppendChild(doc.CreateElement(
"
image
"
));
XmlElement elmtData
=
doc.CreateElement(
"
data
"
);
elmtData.InnerText
=
s;
doc.DocumentElement.AppendChild(elmtData);
doc.Save(
"
test.xml
"
);
}
//
从 XML 文件中读取图片信息
private
void
button1_Click(
object
sender, System.EventArgs e)
{
XmlDocument doc
=
new
XmlDocument();
doc.Load(
"
test.xml
"
);
string
s
=
doc.DocumentElement.SelectSingleNode(
"
data
"
).InnerText;
byte
[] b
=
Convert.FromBase64String(s);
MemoryStream stream
=
new
MemoryStream(b);
Bitmap bitmap
=
new
Bitmap(stream);
this
.pictureBox1.Image
=
bitmap;
}
查看全文
相关阅读:
2020年12月15日Java学习日记
2020年12月12日Java学习日记
2020年12月10日Java学习日记
2020年12月8日Java学习日记
2020年12月4日Java学习日记
2020年12月1日Java学习日记
2020年11月30日Java学习日记
2020年11月27日Java学习日记
2020年11月26日Java学习日记
B. Navigation System【CF 1320】
原文地址:https://www.cnblogs.com/RChen/p/230763.html
最新文章
roblox OA lifting weights 自己根据subsets改的
Wepay OA
反片语(Ananagrams , UVa 156)
安迪的第一个字典(Andy's First Dictionary , UVa 10815)
木块问题(The Blocks Problem. UVa 101)
大理石在哪(Where is the Marble?,UVa 10474)
springboot简单面试题
springboot学习(十一)UserAgentUtils
springboot学习(十)Spring Boot Admin
springboot学习(九)自动装配和Actuator
热门文章
springboot学习(八)热部署和打包
springboot学习(七)安全管理 spring security
springboot学习(六)整合缓存框架
springboot学习(五)整合NoSQL
springboot学习(四)整合MyBatis
springboot学习(三)整合web开发
linux的一些记录
mysql的主从配置(docker-conetos7)
mysql的慢查询日志
2020年12月18日Java学习日记
Copyright © 2011-2022 走看看