1

我正在编写一个 Windows 8 应用程序,它应该根据本地存储中的图像更改磁贴。

首先,我将来自 url 的图像存储到本地存储中:

         const string fileName = "test.jpg";
        StorageFile storageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

        using (IRandomAccessStream storageStream = await storageFile.OpenAsync(FileAccessMode.ReadWrite))
        {
            HttpClient client = new HttpClient();
            Stream imageStream = await client.GetStreamAsync("http://suntsu.smugmug.com/Public/NikonTest/i-5L8JLTz/0/Th/20120124_Nikon_Macro_2-Th.jpg");

            using (var memoryStream = new MemoryStream())
            {
                imageStream.CopyTo(memoryStream);
            }
            await RandomAccessStream.CopyAndCloseAsync(imageStream.AsInputStream(), destination: storageStream.GetOutputStreamAt(0));
        }

这有效,我可以通过以下方式访问文件:

  //var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri( "ms-appdata:///local/" + fileName));

现在我想将此图像添加为我的新直播:

            XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideImageAndText01);
        XmlNodeList tileTextElements = tileXml.GetElementsByTagName("text");
        tileTextElements.Item(0).AppendChild(tileXml.CreateTextNode(fileName));
        XmlNodeList tileImageAttributes = tileXml.GetElementsByTagName("image");
        tileImageAttributes[0].Attributes[1].NodeValue = "ms-appdata:///local/" + fileName;

现在的问题是什么都没有发生,并且我的磁贴中没有显示任何图像。

我猜这个问题与“ms-appdata:///local/”+文件名有关;,因为如果我使用代码从我的应用程序文件夹加载文件,它就可以工作。"ms-appx:///images/graySquare.png";

问题:是“ms-appdata:///local/”+文件名;为了将链接设置到本地存储中的图像,错误?以及必须如何完成?

编辑:我忘了添加应该添加新创建的图块的代码。

                ScheduledTileNotification tileNotification = new ScheduledTileNotification(tileXml, DateTimeOffset.UtcNow.AddSeconds(count));
            TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);
            TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(tileNotification);

编辑:是否有可能验证“ms-appdata:///local/myimage.jpg”以确保此 uri 正确且图像存在?

4

1 回答 1

1

I found it. The problem was not the path. "ms-appdata:///local/myimage.jpg" was correct. The code for writing the files is not correct, and so there only were 0 byte images. This did not cause any exceptions or messages, but the tile was not updated.

于 2012-12-15T16:03:40.230 回答