以文本方式查看主题 - W3CHINA.ORG讨论区 - 语义网·描述逻辑·本体·RDF·OWL (http://bbs.xml.org.cn/index.asp) -- 『 DOM/SAX/XPath 』 (http://bbs.xml.org.cn/list.asp?boardid=11) ---- dom方式如何将图片转到binhex方式存入xml文件中?.net2003环境 (http://bbs.xml.org.cn/dispbbs.asp?boardid=11&rootid=&id=20828) |
-- 作者:doggod2008 -- 发布时间:8/1/2005 8:41:00 PM -- dom方式如何将图片转到binhex方式存入xml文件中?.net2003环境 ![]() |
-- 作者:Qr -- 发布时间:8/1/2005 8:46:00 PM -- 试试nodeTypeDvalue的bin.base64 |
-- 作者:doggod2008 -- 发布时间:8/1/2005 8:49:00 PM -- base64跟binhex有什么区别阿?好像base64产生的图像大一些吧 |
-- 作者:doggod2008 -- 发布时间:8/1/2005 8:55:00 PM -- Qr同学,我回去试一下,如果问题解决了 && 你是csdn的会员的话,可以到 http://community.csdn.net/Expert/topic/4182/4182180.xml?temp=.5377313 和 http://community.csdn.net/Expert/topic/4179/4179828.xml?temp=.9892694 接分,呵呵 |
-- 作者:doggod2008 -- 发布时间:8/1/2005 9:01:00 PM -- 又找着了这么个帖子:大家分享 private XmlDocument document; private string FilePath = Application.StartupPath + "\\..\\..\\FormStyle.xml"; // FormStyle.xml 文件地址 private void frmMain_Load(object sender, System.EventArgs e) { if(document == null) { document = new XmlDocument(); document.Load(FilePath); } // 只挑选含有Form的节点 XmlNodeList FormNodes = document.GetElementsByTagName("Form"); lbIcons.BeginUpdate(); lbIcons.Items.Clear(); foreach(XmlNode node in FormNodes) { // 把节点的名称放到下拉列表里 lbIcons.Items.Add(node.Attributes["Name"].Value); } lbIcons.EndUpdate(); } private void lbIcons_SelectedValueChanged(object sender, System.EventArgs e) { // 查找下拉框所选的窗体下是否有Image元素,若无则退出 XmlNode node = document.DocumentElement.SelectSingleNode(string.Format("descendant::Form[@Name='{0}']/Image", lbIcons.SelectedItem.ToString())); if(node == null) return; // 如果含有Image元素,就将元素值转换为Base64String,然后放到内存流 using (MemoryStream mem = new MemoryStream(Convert.FromBase64String(node.InnerText))) { // 加载内存流数据为位图 Bitmap bmp = Bitmap.FromStream(mem) as Bitmap; pictureBox1.Image = bmp; } } private void btnAdd_Click(object sender, System.EventArgs e) { // 如果不存在txtFilePath.Text所指文件,就退出 if(!File.Exists(txtFilePath.Text) || 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); } |
-- 作者:Qr -- 发布时间:8/1/2005 9:10:00 PM -- 没注意,那就用bin.binhex吧:)
|
-- 作者:Qr -- 发布时间:8/1/2005 9:11:00 PM -- 前者经BASE64加密,后者是16进制。 |
-- 作者:doggod2008 -- 发布时间:8/1/2005 10:39:00 PM -- base64怎么转化到binhex的?Qr大哥不吝赐教阿.... |
-- 作者:Qr -- 发布时间:8/1/2005 10:58:00 PM -- 没有做过,直接用bin.binhex就行。 |
-- 作者:doggod2008 -- 发布时间:8/1/2005 11:16:00 PM -- 我查了一下,nodeTypeDvalue是Microsoft XML 3.0 的接口,我用的基本上是System.Xml空间的类,所以不知道怎么用nodetypedValue |
-- 作者:doggod2008 -- 发布时间:8/1/2005 11:23:00 PM -- 算了,还是用base64吧,直接的函数还较多,非常感谢Qr大哥 |
-- 作者:Qr -- 发布时间:8/1/2005 11:26:00 PM -- System.Xml,偶也没注意其是否用nodetypedvalue或相应的东东:)经你提醒,偶想起来nodetypedvalue的确是MSXML的接口。 |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
66.406ms |