惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News | PayPal Newsroom
P
Proofpoint News Feed
Cyberwarzone
Cyberwarzone
C
Cisco Blogs
SecWiki News
SecWiki News
Know Your Adversary
Know Your Adversary
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Vercel News
Vercel News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
NISL@THU
NISL@THU
WordPress大学
WordPress大学
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Threat Research - Cisco Blogs
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
Security Archives - TechRepublic
Security Archives - TechRepublic
有赞技术团队
有赞技术团队
L
LINUX DO - 热门话题
Hacker News: Ask HN
Hacker News: Ask HN
V
V2EX
G
GRAHAM CLULEY
TaoSecurity Blog
TaoSecurity Blog
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
F
Fortinet All Blogs
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
Latest news
Latest news
The Hacker News
The Hacker News
aimingoo的专栏
aimingoo的专栏
T
Troy Hunt's Blog
S
Schneier on Security
I
Intezer
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threatpost
爱范儿
爱范儿
The Register - Security
The Register - Security
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
宝玉的分享
宝玉的分享
Recent Commits to openclaw:main
Recent Commits to openclaw:main
美团技术团队
B
Blog RSS Feed

博客园 - Xfan

TextBox只能输入数字[转] - Xfan - 博客园 Oracle Sql 语法收集[转] 计算机类期刊投稿心得(转贴) 对生活和工作很有用的箴言 一个功能齐全的DataGrid分页例子 Oracle中正确利用Rownum来限制查询所返回的行数 Oracle中取某时间段月份列表 Linux安装的必要知识 常见的UNIX版本说明 免费软件大名单公布 - Xfan - 博客园 全方位解析RPR技术 IP环网技术 IP环网技术综述与实现 [积累]c#.net常用函数 [藏]通过.NET访问Oracle数据库 [转]Oracle简单示例讲解 [总结]Oracle数据导入导出imp/exp System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.的解决方案 官方水晶报表.NET 应用程序实例下载(C#、Visual C++.NET)
如何把一个图像存储到XML数据中,并读取出来
Xfan · 2006-08-30 · via 博客园 - Xfan

读取图像

//定义图像源与目标xml文件

string ImgFileName = @"d:\中国移动暴强广告.JPG";

string XmlFileName = @"D:\img.xml";

XmlTextWriter aXmlTextWriter = new XmlTextWriter(XmlFileName, System.Text.Encoding.Default);

aXmlTextWriter.Formatting = Formatting.Indented;

       try

              {                         

                  aXmlTextWriter.WriteStartDocument();

                     aXmlTextWriter.WriteComment("Contains a BinHex JPEG image");

                     aXmlTextWriter.WriteStartElement("jpeg");

                     //下边就是通用的读取图像的代码

                     System.IO.FileInfo fi = new System.IO.FileInfo(ImgFileName);

                     int size = (int)fi.Length;

                     //read the jpeg file

                     byte []img = new byte[size];

System.IO.FileStream fs = new System.IO.FileStream(ImgFileName, System.IO.FileMode.Open);

                     System.IO.BinaryReader br = new System.IO.BinaryReader(fs);

                     img = br.ReadBytes(size);

                     br.Close();

                     //注意这里用的是BinHex编码

                     aXmlTextWriter.WriteBinHex(img,0,size);

                     aXmlTextWriter.WriteEndDocument();

              }

              catch(XmlException xmlE)

              {

                     Response.Write(xmlE.Message);

              }

              finally

              {

                     aXmlTextWriter.Close();

              }

显示图像

简单的在窗口中放一个PictureBox,在一个按钮中写如下代码

string XmlFileName = @"D:\img.xml";

XmlTextReader aXmlTextReader = new XmlTextReader(XmlFileName);

aXmlTextReader.Read();

aXmlTextReader.MoveToContent();

if(aXmlTextReader.LocalName == "jpeg")

    {

        System.IO.FileInfo fi = new System.IO.FileInfo(XmlFileName);

        int iSize = (int)fi.Length;

        byte []img = new byte[iSize];

        aXmlTextReader.ReadBinHex(img,0,iSize);

        //Byte to image object

        System.IO.MemoryStream ms = new System.IO.MemoryStream();

        ms.Write(img,0,iSize);

        Bitmap bmp = new Bitmap(ms);

        ms.Close();

        this.pictureBox1.Image = bmp;

}

aXmlTextReader.Close();