盾怪网教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

.Net中将图片数据保存到XML文档

时间:2024/11/27作者:未知来源:盾怪网教程人气:

[摘要]lbIcons.Items.Count == 0) return; if(lbIcons.SelectedIndex == -1) ...
lbIcons.Items.Count == 0)
              return;
 
       if(lbIcons.SelectedIndex == -1)
              lbIcons.SelectedIndex = 0;
 
       if(document == null)
       {
              document = new XmlDocument();
              document.Load(FilePath);
       }
 
       //Read the bitmap.
       string data = null;
       Bitmap bmp = new Bitmap(txtFilePath.Text);
       using (MemoryStream mem = new MemoryStream())
       {
              bmp.Save(mem, System.Drawing.Imaging.ImageFormat.Bmp);
              // 将位图数据转换为Base64String放入字符串中
              data = Convert.ToBase64String(mem.ToArray());
       }
 
       // 查找当前所选的窗体是否含有Image节点,若就新建一个
       XmlNode node = document.DocumentElement.SelectSingleNode(string.Format("descendant::Form[@Name='{0}']", lbIcons.SelectedItem.ToString()));
       XmlNode ImageNode = document.DocumentElement.SelectSingleNode(string.Format("descendant::Form[@Name='{0}']/Image", lbIcons.SelectedItem.ToString()));
       if(ImageNode == null)
       {
              ImageNode = document.CreateElement("Image");
              node.AppendChild(ImageNode);
       }
 
       // 将位图数据保存到XML文档
       ImageNode.InnerText = data;
       document.Save(FilePath);
}



关键词:.Net中将图片数据保存到XML文档




Copyright © 2012-2018 盾怪网教程(http://www.dunguai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版