【问题标题】:The component cannot be found. (Exception from HRESULT: 0x88982F50) when setting stream to bitmapimage in windows phone 8 app找不到该组件。 (HRESULT 异常:0x88982F50)在 Windows Phone 8 应用程序中将流设置为位图图像时
【发布时间】:2014-11-17 18:24:47
【问题描述】:

我正在尝试在 xml 中的现有隔离文件夹中添加一个元素 代码:

    public void writeToXML(List<AppTile> appList)
    {
        // Write to the Isolated Storage
        XmlWriterSettings x_W_Settings = new XmlWriterSettings();
        x_W_Settings.Indent = true;
        using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (!ISF.FileExists("config.xml"))
            {

                using (IsolatedStorageFileStream stream = ISF.OpenFile("config.xml", FileMode.CreateNew))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(List<AppTile>));
                    using (XmlWriter xmlWriter = XmlWriter.Create(stream, x_W_Settings))
                    {

                        serializer.Serialize(xmlWriter, appList);

                    }
                    stream.Close();
                }

            }
            else
            {

                string tileName = null;
                string url = null;
                string key = null;
                byte [] tilePic = null;
                XDocument loadedData;
                if (appList != null)
                {
                    foreach (AppTile app in appList)
                    {
                        tileName = app.TileName;
                        url = app.Url;
                        key = app.Key;
                        tilePic = app.TilePic;
                       // tilePic = Encoding.UTF8.GetString(app.TilePic,0,app.TilePic.Length);
                       // tilePic = Encoding.Unicode.GetString(app.TilePic,0,app.TilePic.Length);
                       // var writer = new BinaryWriter(tilePic);


                    }
                    using (Stream stream = ISF.OpenFile("config.xml", FileMode.Open, FileAccess.ReadWrite))
                    {

                        loadedData = XDocument.Load(stream);
                        var RootNode = new XElement("AppTile");

                        RootNode.Add(new XElement("TileName", tileName));
                        RootNode.Add(new XElement("Key", key));
                        RootNode.Add(new XElement("Url", url));
                        RootNode.Add(new XElement("TilePic", tilePic));

                        // Find Root Element And Descedents and Append New Node After That
                        var root = loadedData.Element("ArrayOfAppTile");
                        var rows = root.Descendants("AppTile");
                        var lastRow = rows.Last();
                        lastRow.AddAfterSelf(RootNode);
                    }

                    // Save To ISOconfig.xml File 
                    using (IsolatedStorageFileStream newStream = new IsolatedStorageFileStream("config.xml", FileMode.Create, ISF))
                    {
                        loadedData.Save(newStream);
                        newStream.Close();
                    }
                }

            }
        }
    }

从 xml 读取时,我正在使用 xmlWriter 并将其反序列化以获取 List 当我尝试访问 AppTile 类型的 tilePic 时,我收到错误:找不到组件。使用以下代码:: 图片 img = new Image();

                MemoryStream imgStream = new MemoryStream(NewApp.TilePic);//NewApp is AppTile type
                BitmapImage imgSource = new BitmapImage();
                imgSource.SetSource(imgStream);//here i get error
                img.Source = imgSource;

很可能我保存的 TilePic 格式不正确,无法检索。

请帮忙!!

【问题讨论】:

    标签: windows-phone-8


    【解决方案1】:

    为什么不使用SaveJpeg 扩展方法来创建byte 数组?

    这个可能对你有帮助!

    Windows Phone - byte array to BitmapImage converter throws exception

    【讨论】:

    • 实际上我正在通过服务调用 gwtting 对象应用程序列表......它已经将 xml 的结构(通过序列化)设置为 XboX 此处为字节数组应用程序块url
    【解决方案2】:

    解决了这个问题: 在保存字节数组时,它被编码为读取时无法识别的某种格式,所以我所做的就是将其保存为字符串。所以更新的代码是:

                   else
                  {
                    string tileName = null;
                    string url = null;
                    string key = null;
                    string tilePicString = null;
    
                    XDocument loadedData;
    
                    System.Windows.Media.Imaging.BitmapImage imgSource = new System.Windows.Media.Imaging.BitmapImage();
                    if (appList != null)
                    {
                        foreach (AppTile app in appList)
                        {
                            tileName = app.TileName;
                            url = app.Url;
                            key = app.Key;
                            //changed here
                            tilePicString = System.Convert.ToBase64String(app.TilePic);
    
                        }
                       //same code as above
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 2023-03-26
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多