• 将图片字节数组存储到xml以及从xml读取


    public class RWPhotoXmlUtils
        {
            public  static void WriteXml(string foldName,string fileName,Dictionary<int, byte[]> dict)
            {
                try
                {
                    XElement root = new XElement("Root");
                    foreach (KeyValuePair<int, byte[]> obj in dict)
                    {
                        XElement photo = new XElement("Photo");
                        XElement riderId = new XElement("RiderId", obj.Key);                   
                        string str = System.Convert.ToBase64String(obj.Value);
                        XElement riderPhoto = new XElement("RiderPhoto", str);
                        photo.Add(riderId);
                        photo.Add(riderPhoto);
                        root.Add(photo);
                    }

                    string xmlString = root.ToString();
                    IsolatedStorageUtils.WriteDataToFile(foldName, fileName, xmlString);
                }
                catch (Exception ex)
                {
                    DebugUtils.Debug("Exception occured at RWPhotoXmlUtils.cs WriteXml method:", ex);
                }

            }

            public static Dictionary<int, byte[]> ReadXml(string fileName)
            {
                Dictionary<int, byte[]> dict = new Dictionary<int, byte[]>();
                try
                {
                 
                    string xmlString = IsolatedStorageUtils.ReadDataFromFile(fileName);
                    XElement xml = XElement.Parse(xmlString);            

                    var myCollection = from Photo in xml.Descendants("Photo")
                             select new
                             {
                                 RiderId = Photo.Element("RiderId").Value,
                                 RiderPhoto = Photo.Element("RiderPhoto").Value
                             };

                    foreach (var obj in myCollection)
                    {
                       byte[] bytes =  System.Convert.FromBase64String(obj.RiderPhoto);
                        dict.Add(Int32.Parse(obj.RiderId),  bytes);
                        
                    }


                }
                catch (Exception ex)
                {
                    DebugUtils.Debug("Exception occured at RWPhotoXmlUtils.cs ReadXml method:", ex);
                    
                }
                return dict;

            }     
         
        }

    高山仰止, 景行行止。 四牡鲱鲱, 六辔如琴。 觏尔新婚, 以慰我心。
  • 相关阅读:
    国内外常用学术论文搜索网站
    2019年全国高校sql数据库
    Flask无法访问(127.0.0.1:5000)的问题解决方法
    Windows终端命令行工具Cmder
    JQuery实现密码可见不可见
    区块链最大的难题及其解决方案
    python 下载 进度条
    centos 用docker 运行 cypress
    通过 centos Nginx 查看html (为后续 服务器生成html 方便访问)
    odoo 分享 PostgreSQL 语句2
  • 原文地址:https://www.cnblogs.com/davidshi/p/3338572.html
Copyright © 2020-2023  润新知