日期:2014-05-18 浏览次数:21151 次
XmlElement eleImg = myXmlDoc.CreateElement("image"); string textString = System.Convert.ToBase64String(convImgToByte((Image)tsbLink.Image, tsbLink.Image.RawFormat)); eleImg.InnerText = textString;
/// <summary> /// 图片 转换 byte数组 /// </summary> /// <param name="pic"></param> /// <param name="fmt"></param> /// <returns></returns> public byte[] convImgToByte(System.Drawing.Image pic, System.Drawing.Imaging.ImageFormat fmt) { MemoryStream mem = new MemoryStream(); //①这个报错 pic.Save(mem, fmt); return mem.GetBuffer(); }
XmlElement eleImg = myXmlDoc.CreateElement("image"); var myImage = (Image)tsbLink.Image; string textString = System.Convert.ToBase64String(convImgToByte(myImage , tsbLink.Image.RawFormat)); eleImg.InnerText = textString;
------解决方案--------------------
看看这个:
XML文档中读写图片